diff options
author | Joe Perches <[email protected]> | 2020-12-15 20:44:33 -0800 |
---|---|---|
committer | Linus Torvalds <[email protected]> | 2020-12-15 22:46:17 -0800 |
commit | dc58bc553e7a8e1d6eeaffd92cb8b346e0d62f70 (patch) | |
tree | b80dd90ae5ee32ac7a5e8515b92bd012694d537e | |
parent | 73169765e6e7ac54528778faa592b15df5c8a93c (diff) |
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/[email protected]
Signed-off-by: Joe Perches <[email protected]>
Cc: Julia Lawall <[email protected]>
Cc: Tom Rix <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
-rwxr-xr-x | scripts/checkpatch.pl | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 4018bf89e63a..c128875b6666 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3699,12 +3699,16 @@ sub process { } # 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*$/) { my $tabs = $1; - if ($prevline =~ /^\+$tabs(?:goto|return)\b/) { - WARN("UNNECESSARY_BREAK", - "break is not useful after a goto or return\n" . $hereprev); + if ($prevline =~ /^\+$tabs(goto|return|break)\b/) { + if (WARN("UNNECESSARY_BREAK", + "break is not useful after a $1\n" . $hereprev) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } } } |