Commit d1e2ad07 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

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

Fixed indentation in the other semicolon test above it.
Suggested-by: default avatarPeter Senna Tschudin <>
Signed-off-by: default avatarJoe Perches <>
Cc: Andy Whitcroft <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 88982fea
......@@ -3448,8 +3448,22 @@ sub process {
# check for multiple semicolons
if ($line =~ /;\s*;\s*$/) {
"Statements terminations use 1 semicolon\n" . $herecurr);
"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";
"switch default: should use break\n" . $herectx);
# check for gcc specific __FUNCTION__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment