checkpatch: warn on #defines ending in semicolon
authorJoe Perches <joe@perches.com>
Wed, 4 Jun 2014 23:12:06 +0000 (16:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Jun 2014 23:54:20 +0000 (16:54 -0700)
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 <joe@perches.com>
Cc: Borislav Petkov <bp@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index bb4c8428f3330ee5068e771c7478c282b1cd4141..e7ff52a39ec97e0d5b94b6154dadf021bb937d02 100755 (executable)
@@ -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");
                        }
                }