[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200729125911.47318-1-cambda@linux.alibaba.com>
Date: Wed, 29 Jul 2020 20:59:11 +0800
From: Cambda Zhu <cambda@...ux.alibaba.com>
To: Joe Perches <joe@...ches.com>
Cc: linux-kernel@...r.kernel.org, Cambda Zhu <cambda@...ux.alibaba.com>
Subject: [PATCH] checkpatch: skip macros when finding missing switch/case break
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:
\+#if xxx
\+ case xxx: {
\+ ...
\+ break/return/...;
\+ }
\+#endif
\+#if xxx
\+ case xxx:
\+ ...
\+#endif
This patch skips lines starting with whitespaces and #, so the counter
of previous statements won't increase in these cases.
Signed-off-by: Cambda Zhu <cambda@...ux.alibaba.com>
---
scripts/checkpatch.pl | 1 +
1 file changed, 1 insertion(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..2c0a51ac82a7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6503,6 +6503,7 @@ sub process {
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$;]*$/);
+ 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)/);
--
2.16.6
Powered by blists - more mailing lists