Skip to content

Commit 8105362

Browse files
vignesh-aerlyncdanieldegrasse
authored andcommitted
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>
1 parent 67caf3b commit 8105362

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

scripts/checkpatch.pl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5560,7 +5560,42 @@ sub process {
55605560
$block =~ tr/\x1C//d;
55615561
#print sprintf '%v02X', $block;
55625562
#print "\n";
5563-
if ($level == 0 && $block !~ /^\s*\{/ && !$allowed) {
5563+
5564+
# Detect if the line is part of a macro
5565+
my $is_macro = 0;
5566+
5567+
# Check if the current line is a single-line macro
5568+
if ($lines[$linenr] =~ /^\+\s*#\s*define\b/) {
5569+
$is_macro = 1;
5570+
} else {
5571+
# Dynamically check upward for multi-line macro
5572+
my $i = $linenr - 1;
5573+
while ($i >= 0) {
5574+
my $line = $lines[$i];
5575+
last unless defined $line;
5576+
5577+
# Stop at non-added/context lines
5578+
last if $line !~ /^[ +]/;
5579+
5580+
# If this is a macro definition line, we're inside a macro
5581+
if ($line =~ /^\+\s*#\s*define\b/) {
5582+
$is_macro = 1;
5583+
last;
5584+
}
5585+
5586+
# Check if previous line ends with backslash (i.e., continuation)
5587+
if ($i > 0) {
5588+
my $prev_line = $lines[$i - 1];
5589+
last if !defined($prev_line) || $prev_line !~ /\\\s*$/;
5590+
} else {
5591+
last;
5592+
}
5593+
5594+
$i--;
5595+
}
5596+
}
5597+
5598+
if ($level == 0 && $block !~ /^\s*\{/ && !$allowed && !$is_macro) {
55645599
my $cnt = statement_rawlines($block);
55655600
my $herectx = get_stat_here($linenr, $cnt, $here);
55665601

0 commit comments

Comments
 (0)