checkpatch: Avoid declaration spacing checks for asm statements
PATCH 1/1 checkpatch: Avoid declaration spacing checks for asm statements
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.
---
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(+)
scripts/checkpatch.pl +17 -0
@@ -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,
Signature · 1 line
Jia Wang <[email protected]>