diff options
author | Joe Perches <joe@perches.com> | 2012-07-30 17:41:24 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 20:25:17 -0400 |
commit | b13edf7ff2dd0fef95e981170fa71fa6b60421b0 (patch) | |
tree | cdfbfb5429b089d1e41f9551bf112a8236fae078 /scripts | |
parent | 66c80b6077256898df948ac6acf547b47ddb1fcf (diff) |
checkpatch: add checks for do {} while (0) macro misuses
These types of macros should not be used for either a single statement
nor should the macro end with a semi-colon.
Add tests for these conditions.
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 40b0627aeb5e..913d6bdfdda3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -2988,6 +2988,45 @@ sub process { | |||
2988 | } | 2988 | } |
2989 | } | 2989 | } |
2990 | 2990 | ||
2991 | # do {} while (0) macro tests: | ||
2992 | # single-statement macros do not need to be enclosed in do while (0) loop, | ||
2993 | # macro should not end with a semicolon | ||
2994 | if ($^V && $^V ge 5.10.0 && | ||
2995 | $realfile !~ m@/vmlinux.lds.h$@ && | ||
2996 | $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) { | ||
2997 | my $ln = $linenr; | ||
2998 | my $cnt = $realcnt; | ||
2999 | my ($off, $dstat, $dcond, $rest); | ||
3000 | my $ctx = ''; | ||
3001 | ($dstat, $dcond, $ln, $cnt, $off) = | ||
3002 | ctx_statement_block($linenr, $realcnt, 0); | ||
3003 | $ctx = $dstat; | ||
3004 | |||
3005 | $dstat =~ s/\\\n.//g; | ||
3006 | |||
3007 | if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) { | ||
3008 | my $stmts = $2; | ||
3009 | my $semis = $3; | ||
3010 | |||
3011 | $ctx =~ s/\n*$//; | ||
3012 | my $cnt = statement_rawlines($ctx); | ||
3013 | my $herectx = $here . "\n"; | ||
3014 | |||
3015 | for (my $n = 0; $n < $cnt; $n++) { | ||
3016 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
3017 | } | ||
3018 | |||
3019 | if (($stmts =~ tr/;/;/) == 1) { | ||
3020 | WARN("SINGLE_STATEMENT_DO_WHILE_MACRO", | ||
3021 | "Single statement macros should not use a do {} while (0) loop\n" . "$herectx"); | ||
3022 | } | ||
3023 | if (defined $semis && $semis ne "") { | ||
3024 | WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON", | ||
3025 | "do {} while (0) macros should not be semicolon terminated\n" . "$herectx"); | ||
3026 | } | ||
3027 | } | ||
3028 | } | ||
3029 | |||
2991 | # make sure symbols are always wrapped with VMLINUX_SYMBOL() ... | 3030 | # make sure symbols are always wrapped with VMLINUX_SYMBOL() ... |
2992 | # all assignments may have only one of the following with an assignment: | 3031 | # all assignments may have only one of the following with an assignment: |
2993 | # . | 3032 | # . |