All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] regmap: guard DEFINE_FREE(regmap_field) against ERR_PTR values
@ 2026-11-20 19:04 Elkin Cruz
  0 siblings, 0 replies; only message in thread
From: Elkin Cruz @ 2026-11-20 19:04 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, llvm, irogers, Elkin Cruz

regmap_field_alloc() returns ERR_PTR() on allocation failure, never NULL.
DEFINE_FREE(regmap_field, ...) currently checks only if (_T), which is
true for ERR_PTR() values and causes __free(regmap_field) variables on
error paths to pass an error pointer into regmap_field_free() -> kfree().

Guard the cleanup macro with !IS_ERR_OR_NULL(_T).

Fixes: 37983fad7f3e ("regmap: define cleanup helper for regmap_field")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
I am trying out a new Clang static analysis linter for ERR_PTR/NULL
handling, and it flagged this code as possibly buggy. The findings were triaged
and fixed with an AI coding assistant, then checked against linux-next (not
runtime-tested on hardware).

Thanks,
Elkin

 include/linux/regmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 8f3034881f8a..572dd6f0083d 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1484,7 +1484,7 @@ struct regmap_field *regmap_field_alloc(struct regmap *regmap,
 		struct reg_field reg_field);
 void regmap_field_free(struct regmap_field *field);
 
-DEFINE_FREE(regmap_field, struct regmap_field *, if (_T) regmap_field_free(_T))
+DEFINE_FREE(regmap_field, struct regmap_field *, if (!IS_ERR_OR_NULL(_T)) regmap_field_free(_T))
 
 struct regmap_field *devm_regmap_field_alloc(struct device *dev,
 		struct regmap *regmap, struct reg_field reg_field);
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 19:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 19:04 [PATCH] regmap: guard DEFINE_FREE(regmap_field) against ERR_PTR values Elkin Cruz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.