From: Jia Wang <wangjia@ultrarisc.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>
Cc: linux-kernel@vger.kernel.org, Jia Wang <wangjia@ultrarisc.com>
Subject: [PATCH] checkpatch: Avoid declaration spacing checks for asm statements
Date: Thu, 16 Jul 2026 10:56:57 +0800 [thread overview]
Message-ID: <20260716-checkpatch-v1-1-3f5adf4cdc85@ultrarisc.com> (raw)
The declaration spacing check uses C-oriented heuristics. In headers
that contain assembler code, those heuristics can mistake instructions
with comma-separated operands for declarations.
Assembler headers across architectures can contain operand shapes that
look like C declarations, and inline block comments can contain
punctuation that should not prevent an assembler statement from being
recognized.
Teach the check to recognize assembler statement shapes in files that
can contain assembler code, after ignoring inline block comments, and
skip only this declaration spacing test for those lines. Normal C
declaration spacing checks are unchanged.
Signed-off-by: Jia Wang <wangjia@ultrarisc.com>
---
checkpatch's declaration spacing check uses C-oriented heuristics and can
mistake assembler instructions with comma-separated operands for C
declarations. This can trigger false LINE_SPACING warnings in headers
that contain assembler code.
Avoid the false positive by recognizing assembler statement shapes in
files that may contain assembler code. Strip inline block comments before
matching so punctuation inside comments does not prevent an assembler
statement from being recognized. Only this declaration spacing test is
skipped for matching assembler lines; normal C declaration spacing checks
are unchanged.
Validation covered the original asm-header reproducer, cross-architecture
assembler operand samples, C declaration regression samples, and inline
block comment cases. The HEAD patch passes:
perl -c scripts/checkpatch.pl
git format-patch -1 --stdout HEAD | scripts/checkpatch.pl --strict -
---
scripts/checkpatch.pl | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2b7a42bbdd94..bb307d49fc86 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1141,6 +1141,21 @@ sub deparenthesize {
return $string;
}
+sub is_asm_statement {
+ my ($realfile, $line) = @_;
+
+ return 0 if (!defined($line));
+ return 0 if ($realfile !~ /\.(?:h|s|S)$/);
+
+ $line =~ s/^[\+ ]\s*//;
+ $line =~ s@/\*.*?\*/@@g;
+
+ return 0 if ($line =~ /[;{}]/);
+ return 1 if ($line =~ /^(?:[A-Za-z_.\$][\w.\$]*:\s*)?\.?[A-Za-z_][\w.]*\s+[^,]+,\s*.+$/);
+
+ return 0;
+}
+
sub seed_camelcase_file {
my ($file) = @_;
@@ -4186,6 +4201,8 @@ sub process {
$pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
# known declaration macros
$pl =~ /^\+\s+$declaration_macros/) &&
+ # assembler statements can look like declarations
+ !is_asm_statement($realfile, $prevrawline) &&
# for "else if" which can look like "$Ident $Ident"
!($pl =~ /^\+\s+$c90_Keywords\b/ ||
# other possible extensions of declaration lines
---
base-commit: 58717b2a1365d06c8c64b72aa948541b53fe31eb
change-id: 20260716-checkpatch-47daa5fa23cb
Best regards,
--
Jia Wang <wangjia@ultrarisc.com>
reply other threads:[~2026-07-16 2:57 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=20260716-checkpatch-v1-1-3f5adf4cdc85@ultrarisc.com \
--to=wangjia@ultrarisc.com \
--cc=apw@canonical.com \
--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®