checkpatch: Fix bad COMPLEX_MACRO on asm volatile
PATCH 1/1 checkpatch: Fix bad COMPLEX_MACRO on asm volatile
Commit 42e152931deb ("checkpatch: exclude asm volatile from complex macro check") added a substitution converting "asm volatile" into "asm_volatile" so that macros expanding to an asm volatile statement would be treated like a single function call and excluded from the COMPLEX_MACRO error ("Macros with complex values should be enclosed in parentheses").
However, that substitution was placed after the loop that flattens parenthesized expressions into "1u" (originally "1"). For a macro without whitespace between "volatile" and "(", such as:
#define foo(x) asm volatile("..." : : "r" (x))flattening the parenthesized argument list first turns the statement into "asm volatile1u". Because "1u" starts with a word character, the trailing word boundary (\b) in /\b_*asm_*\s+_*volatile_*\b/ no longer matches after "volatile", leaving the space between "asm" and "volatile1u" intact and causing the macro to still fail the single-lvalue check and trigger a false-positive COMPLEX_MACRO error.
Move the "asm volatile" to "asm_volatile" substitution before the parenthesis-flattening loop so that "asm volatile(...)" is first rewritten to "asm_volatile(...)" and then flattened to "asm_volatile1u" as intended.
--- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +3 -3
@@ -6050,6 +6050,9 @@ sub process { $dstat =~ s/^\s*//s; $dstat =~ s/\s*$//s; + # Make asm volatile uses seem like a generic function + $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g; + # Flatten any parentheses and braces while ($dstat =~ s/\([^\(\)]*\)/1u/ || $dstat =~ s/\{[^\{\}]*\}/1u/ ||
@@ -6063,9 +6066,6 @@ sub process { { } - # Make asm volatile uses seem like a generic function - $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g; - my $exceptions = qr{ $Declare| # named exceptions
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-checkpatch-asm-complex_macro-75ee815da528
Best regards,
Signature · 1 line
Pierre-Clément Tosi <[email protected]>
Quoted 5 lines · Pierre-Clément Tosi
Commit
42e152931deb("checkpatch: exclude asm volatile from complex macro check") added a substitution converting "asm volatile" into "asm_volatile" so that macros expanding to an asm volatile statement would be treated like a single function call and excluded from theCOMPLEX_MACROerror ("Macros with complex values should be enclosed in parentheses").
Thanks.
Quoted 54 lines
However, that substitution was placed after the loop that flattens parenthesized expressions into "1u" (originally "1"). For a macro without whitespace between "volatile" and "(", such as:
#define foo(x) asm volatile("..." : : "r" (x))flattening the parenthesized argument list first turns the statement into "asm volatile1u". Because "1u" starts with a word character, the trailing word boundary (\b) in /\b_*asm_*\s+_*volatile_*\b/ no longer matches after "volatile", leaving the space between "asm" and "volatile1u" intact and causing the macro to still fail the single-lvalue check and trigger a false-positive
COMPLEX_MACROerror.Move the "asm volatile" to "
asm_volatile" substitution before the parenthesis-flattening loop so that "asm volatile(...)" is first rewritten to "asm_volatile(...)" and then flattened to "asm_volatile1u" as intended.Fixes 42e152931deb ("checkpatch: exclude asm volatile from complex macro check")Signed-off-by Pierre-Clément Tosi <[email protected]>--- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/checkpatch.pl +3
-4@@ -6050,6 +6050,9 @@ sub process { $dstat =~ s/^\s*//s; $dstat =~ s/\s*$//s; + # Make asm volatile uses seem like a generic function + $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g; + # Flatten any parentheses and braces while ($dstat =~ s/\([^\(\)]*\)/1u/ || $dstat =~ s/\{[^\{\}]*\}/1u/ ||@@ -6063,9 +6066,6 @@ sub process { { } - # Make asm volatile uses seem like a generic function - $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g; - my $exceptions = qr{ $Declare| # named exceptions ---base-commit:
6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261107-checkpatch-asm-complex_macro-75ee815da528Best regards,