From: Joe Perches Date: Tue, 18 Dec 2012 00:02:01 +0000 (-0800) Subject: checkpatch: add --strict test for switch/default missing break X-Git-Tag: upstream/snapshot3+hdmi~6031^2~97 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1e2ad07e78c4bbac9fce4d2e3c0fe60bce091d8;p=platform%2Fadaptation%2Frenesas_rcar%2Frenesas_kernel.git 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 Signed-off-by: Joe Perches Cc: Andy Whitcroft Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f27b0b5..725c596 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__