regmap: guard DEFINE_FREE(regmap_field) against ERR_PTR values
PATCH 1/1 regmap: guard DEFINE_FREE(regmap_field) against ERR_PTR values
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 <[email protected]>
---
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(-)
include/linux/regmap.h +1 -1
@@ -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);
Signature · 1 line
2.56.1.750.gf70dc682cf-goog