Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
From: Elkin Cruz <elkin@google.com>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	irogers@google.com,  Elkin Cruz <elkin@google.com>
Subject: [PATCH] regmap: guard DEFINE_FREE(regmap_field) against ERR_PTR values
Date: Fri, 20 Nov 2026 19:04:42 +0000	[thread overview]
Message-ID: <20261120190442.2851983-1-elkin@google.com> (raw)

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


                 reply	other threads:[~2026-11-20 19:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120190442.2851983-1-elkin@google.com \
    --to=elkin@google.com \
    --cc=broonie@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox