[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1404849460.932.35.camel@joe-AO725>
Date: Tue, 08 Jul 2014 12:57:40 -0700
From: Joe Perches <joe@...ches.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Fabian Frederick <fabf@...net.be>
Cc: Antti Palosaari <crope@....fi>, linux-kernel@...r.kernel.org,
Mauro Carvalho Chehab <m.chehab@...sung.com>,
linux-media@...r.kernel.org, Andy Whitcroft <apw@...onical.com>
Subject: [PATCH] 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@...ches.com>
---
> AFAIK there's still no automatic detection of those cases.
There can be now...
scripts/checkpatch.pl | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 496f9ab..fc22f22 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2439,6 +2439,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",
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists