Commit dc58bc55 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: allow --fix removal of unnecessary break statements

switch/case use of break after a return, goto or break is unnecessary.

There is an existing warning for the return and goto uses, so add
break and a --fix option too.

Link: https://lkml.kernel.org/r/d9ea654104d55f590fb97d252d64a66b23c1a096.camel@perches.comSigned-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Julia Lawall <julia.lawall@inria.fr>
Cc: Tom Rix <trix@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 73169765
...@@ -3699,12 +3699,16 @@ sub process { ...@@ -3699,12 +3699,16 @@ sub process {
} }
# check indentation of a line with a break; # check indentation of a line with a break;
# if the previous line is a goto or return and is indented the same # of tabs # if the previous line is a goto, return or break
# and is indented the same # of tabs
if ($sline =~ /^\+([\t]+)break\s*;\s*$/) { if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
my $tabs = $1; my $tabs = $1;
if ($prevline =~ /^\+$tabs(?:goto|return)\b/) { if ($prevline =~ /^\+$tabs(goto|return|break)\b/) {
WARN("UNNECESSARY_BREAK", if (WARN("UNNECESSARY_BREAK",
"break is not useful after a goto or return\n" . $hereprev); "break is not useful after a $1\n" . $hereprev) &&
$fix) {
fix_delete_line($fixlinenr, $rawline);
}
} }
} }
......
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