Skip to content

Commit 2e44e80

Browse files
raydwaipayantorvalds
authored andcommitted
checkpatch: fix multi-statement macro checks for while blocks.
Checkpatch.pl doesn't have a check for excluding while (...) {...} blocks from MULTISTATEMENT_MACRO_USE_DO_WHILE error. For example, running checkpatch.pl on the file mm/maccess.c in the kernel generates the following error: ERROR: Macros with complex values should be enclosed in parentheses +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label) \ + while (len >= sizeof(type)) { \ + __get_kernel_nofault(dst, src, type, err_label); \ + dst += sizeof(type); \ + src += sizeof(type); \ + len -= sizeof(type); \ + } The error is misleading for this case. Enclosing it in parentheses doesn't make any sense. Checkpatch already has an exception list for such common macro types. Added a new exception for while (...) {...} style blocks to the same. In addition, the brace flatten logic was modified by changing the substitution characters from "1" to "1u". This was done to ensure that macros in the form "#define foo(bar) while(bar){bar--;}" were also correctly procecssed. Link: https://lore.kernel.org/linux-kernel-mentees/[email protected]/ Suggested-by: Joe Perches <[email protected]> Signed-off-by: Dwaipayan Ray <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent a0154cd commit 2e44e80

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/checkpatch.pl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5351,9 +5351,9 @@ sub process {
53515351
$dstat =~ s/\s*$//s;
53525352

53535353
# Flatten any parentheses and braces
5354-
while ($dstat =~ s/\([^\(\)]*\)/1/ ||
5355-
$dstat =~ s/\{[^\{\}]*\}/1/ ||
5356-
$dstat =~ s/.\[[^\[\]]*\]/1/)
5354+
while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
5355+
$dstat =~ s/\{[^\{\}]*\}/1u/ ||
5356+
$dstat =~ s/.\[[^\[\]]*\]/1u/)
53575357
{
53585358
}
53595359

@@ -5394,6 +5394,7 @@ sub process {
53945394
$dstat !~ /^\.$Ident\s*=/ && # .foo =
53955395
$dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
53965396
$dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
5397+
$dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
53975398
$dstat !~ /^for\s*$Constant$/ && # for (...)
53985399
$dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
53995400
$dstat !~ /^do\s*{/ && # do {...

0 commit comments

Comments
 (0)