Skip to contentSkip to conversation

checkpatch: skip macros when finding missing switch/case break

PATCH In review Cambda Zhu 2 participants 2 messages Jul 29, 2020 – Jul 31, 2020 Checkpatch

lore
Share & tools
lore

Cambda Zhu

author
#0 lore raw

PATCH 1/1 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.

---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)
scripts/checkpatch.pl +1 -0
index 4c820607540b..2c0a51ac82a7 100755
@@ -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)/);
Signature · 1 line
2.16.6
maintainer
#1 lore raw
Quoted 4 lines · Cambda Zhu

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.