diff options
author | Joe Perches <joe@perches.com> | 2014-08-07 03:11:01 +0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-07 05:01:28 +0400 |
commit | c00df19a5026f2cb08f1770dcc29226512f4d099 (patch) | |
tree | ffc146309723945fac34988eebd0d9a1f2284e53 /scripts | |
parent | 13f1937ef33950b1112049972249e6191b82e6c9 (diff) | |
download | linux-c00df19a5026f2cb08f1770dcc29226512f4d099.tar.xz |
checkpatch: warn on break after goto or return with same tab indentation
Using break; after a goto or return is unnecessary so emit a warning
when the break is at the same indent level.
So this emits a warning on:
switch (foo) {
case 1:
goto err;
break;
}
but not on:
switch (foo) {
case 1:
if (bar())
goto err;
break;
}
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0cf8b98d8dc9..fc72d64cd2d4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2450,6 +2450,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 ($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); + } + } + # discourage the addition of CONFIG_EXPERIMENTAL in #if(def). if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) { WARN("CONFIG_EXPERIMENTAL", |