From: Joe Perches Date: Wed, 4 Jun 2014 23:12:06 +0000 (-0700) Subject: checkpatch: warn on #defines ending in semicolon X-Git-Tag: v6.6-pxa1908~23163^2~16^2~16 X-Git-Url: https://git.dujemihanovic.xyz/?a=commitdiff_plain;h=f5ef95b12eb03ae4b3994cdb035612e127b630b9;p=linux.git checkpatch: warn on #defines ending in semicolon Using a #define ending in a semicolon is poor style and can lead to unexpected code paths being executed. Warn on uses of these #define types: #define foo[(...)] bar; #define foo[(...)] \ bar; Based on a patch from Borislav Petkov. Signed-off-by: Joe Perches Cc: Borislav Petkov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bb4c8428f333..e7ff52a39ec9 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3821,6 +3821,17 @@ sub process { WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON", "do {} while (0) macros should not be semicolon terminated\n" . "$herectx"); } + } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) { + $ctx =~ s/\n*$//; + my $cnt = statement_rawlines($ctx); + my $herectx = $here . "\n"; + + for (my $n = 0; $n < $cnt; $n++) { + $herectx .= raw_line($linenr, $n) . "\n"; + } + + WARN("TRAILING_SEMICOLON", + "macros should not use a trailing semicolon\n" . "$herectx"); } }