mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Alison Schofield <alison.schofield@intel.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH RESEND] checkpatch: don't flag ACQUIRE_ERR() assignments in if conditions
Date: Wed, 16 Sep 2026 10:09:21 +0800	[thread overview]
Message-ID: <20260916020921.3480730-1-kanie@linux.alibaba.com> (raw)

ACQUIRE_ERR() and its wrappers, PM_RUNTIME_ACQUIRE_ERR() and
IIO_DEV_ACQUIRE_FAILED(), report whether a conditional cleanup.h guard
was acquired, and drivers consume the result directly in an if
condition:

	if ((rc = ACQUIRE_ERR(mutex_intr, &lock)))
		return rc;

That combined form is the established style at the 49 in-tree call
sites under drivers/cxl and drivers/pci/tsm.c, so ASSIGN_IN_IF fires
there only as a false positive, and every patch touching those lines
carries noise that reviewers have to wave off manually.

Skip the check when the assigned expression is a call to a macro from
that family, matched by the *_ACQUIRE_ERR() / *_ACQUIRE_FAILED() naming
convention of its wrappers. Plain assignments and near-miss identifiers
still get flagged.

Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Discussion leading to this patch, where the false positive showed up on
a cxl patch and covering the wrapper macros was requested as well:

https://lore.kernel.org/linux-cxl/20260910094017.4032170-3-kanie@linux.alibaba.com/

 scripts/checkpatch.pl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8a7787d228a6..fbc500bcfaa1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5777,7 +5777,12 @@ sub process {
 			my ($s, $c) = ($stat, $cond);
 			my $fixed_assign_in_if = 0;
 
-			if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
+			# ACQUIRE_ERR() and its wrappers, e.g. PM_RUNTIME_ACQUIRE_ERR()
+			# and IIO_DEV_ACQUIRE_FAILED(), are intended to be evaluated in
+			# an if condition, with the error assigned in the condition:
+			#	if ((rc = ACQUIRE_ERR(name, &lock)))
+			if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s &&
+			    $c !~ /=\s*\w*ACQUIRE_(?:ERR|FAILED)\s*\(/) {
 				if (ERROR("ASSIGN_IN_IF",
 					  "do not use assignment in if condition\n" . $herecurr) &&
 				    $fix && $perl_version_ok) {

base-commit: 50d05c7c76c96b90462f24debacca971d2e86713
-- 
2.43.7


             reply	other threads:[~2026-09-16  2:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  2:09 Guixin Liu [this message]
2026-09-22 23:32 ` Alison Schofield
2026-09-24  3:35   ` Guixin Liu

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=20260916020921.3480730-1-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=alison.schofield@intel.com \
    --cc=apw@canonical.com \
    --cc=jic23@kernel.org \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®