summaryrefslogtreecommitdiff
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2012-12-18 04:02:01 +0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-12-18 05:15:19 +0400
commitd1e2ad07e78c4bbac9fce4d2e3c0fe60bce091d8 (patch)
tree41193684d79788aef5d00c817ba570c27c7de02f /scripts/checkpatch.pl
parent88982fea52d0115d44b77619afef576f24cdb844 (diff)
downloadlinux-d1e2ad07e78c4bbac9fce4d2e3c0fe60bce091d8.tar.xz
checkpatch: add --strict test for switch/default missing break
switch default case is sometimes written as "default:;". This can cause new cases added below the default to be defective. Suggest adding a break; after empty default cases to avoid fallthrough defects. Fixed indentation in the other semicolon test above it. Suggested-by: Peter Senna Tschudin <peter.senna@gmail.com> 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/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl18
1 files changed, 16 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f27b0b53e3ea..725c59611e97 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3448,8 +3448,22 @@ sub process {
# check for multiple semicolons
if ($line =~ /;\s*;\s*$/) {
- WARN("ONE_SEMICOLON",
- "Statements terminations use 1 semicolon\n" . $herecurr);
+ WARN("ONE_SEMICOLON",
+ "Statements terminations use 1 semicolon\n" . $herecurr);
+ }
+
+# check for switch/default statements without a break;
+ if ($^V && $^V ge 5.10.0 &&
+ defined $stat &&
+ $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
+ my $ctx = '';
+ my $herectx = $here . "\n";
+ my $cnt = statement_rawlines($stat);
+ for (my $n = 0; $n < $cnt; $n++) {
+ $herectx .= raw_line($linenr, $n) . "\n";
+ }
+ WARN("DEFAULT_NO_BREAK",
+ "switch default: should use break\n" . $herectx);
}
# check for gcc specific __FUNCTION__