Browse Source

scripts: checkpatch: False alarm warning for macros.

Remove false alarm warning of
`braces {} are required around if/while/for/else`
for macro definitions with if/while/for/else.

Signed-off-by: Vignesh Pandian <vignesh@aerlync.com>
pull/92460/head
Vignesh Pandian 2 weeks ago committed by Daniel DeGrasse
parent
commit
810536251d
  1. 37
      scripts/checkpatch.pl

37
scripts/checkpatch.pl

@ -5560,7 +5560,42 @@ sub process { @@ -5560,7 +5560,42 @@ sub process {
$block =~ tr/\x1C//d;
#print sprintf '%v02X', $block;
#print "\n";
if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
# Detect if the line is part of a macro
my $is_macro = 0;
# Check if the current line is a single-line macro
if ($lines[$linenr] =~ /^\+\s*#\s*define\b/) {
$is_macro = 1;
} else {
# Dynamically check upward for multi-line macro
my $i = $linenr - 1;
while ($i >= 0) {
my $line = $lines[$i];
last unless defined $line;
# Stop at non-added/context lines
last if $line !~ /^[ +]/;
# If this is a macro definition line, we're inside a macro
if ($line =~ /^\+\s*#\s*define\b/) {
$is_macro = 1;
last;
}
# Check if previous line ends with backslash (i.e., continuation)
if ($i > 0) {
my $prev_line = $lines[$i - 1];
last if !defined($prev_line) || $prev_line !~ /\\\s*$/;
} else {
last;
}
$i--;
}
}
if ($level == 0 && $block !~ /^\s*\{/ && !$allowed && !$is_macro) {
my $cnt = statement_rawlines($block);
my $herectx = get_stat_here($linenr, $cnt, $here);

Loading…
Cancel
Save