[PATCH] checkpatch: Remove missing switch/case break test

From: Joe Perches
Date: Sat Aug 01 2020 - 12:05:32 EST


This test doesn't work well and newer compilers are much better
at emitting this warning.

Signed-off-by: Joe Perches <joe@xxxxxxxxxxx>
---
> å 2020å8æ1æï02:05ïJoe Perches <joe@xxxxxxxxxxx> åéï
> > ïOn Wed, 2020-07-29 at 20:59 +0800, Cambda Zhu wrote:
> > > The checkpatch.pl only searches 3 previous lines when finding missing
> > > switch/case break, and macros are treated as normal statements. If the
> > > cases are surrounded with CONFIG, checkpatch.pl may report false
> > > warnings. For example:
> >
> > Likely this test should be removed altogether as
> > it's never really worked well and now compilers
> > find this and emit warnings.

scripts/checkpatch.pl | 25 -------------------------
1 file changed, 25 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index cc5542cc234f..4aa1d9d5e62c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6541,31 +6541,6 @@ sub process {
}
}

-# check for case / default statements not preceded by break/fallthrough/switch
- if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
- my $has_break = 0;
- my $has_statement = 0;
- my $count = 0;
- my $prevline = $linenr;
- while ($prevline > 1 && ($file || $count < 3) && !$has_break) {
- $prevline--;
- my $rline = $rawlines[$prevline - 1];
- my $fline = $lines[$prevline - 1];
- last if ($fline =~ /^\@\@/);
- next if ($fline =~ /^\-/);
- next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/);
- $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i);
- next if ($fline =~ /^.[\s$;]*$/);
- $has_statement = 1;
- $count++;
- $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/);
- }
- if (!$has_break && $has_statement) {
- WARN("MISSING_BREAK",
- "Possible switch case/default not preceded by break or fallthrough comment\n" . $herecurr);
- }
- }
-
# check for /* fallthrough */ like comment, prefer fallthrough;
my @fallthroughs = (
'fallthrough',