mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cambda Zhu <cambda@linux.alibaba.com>
To: Joe Perches <joe@perches.com>
Cc: linux-kernel@vger.kernel.org, Cambda Zhu <cambda@linux.alibaba.com>
Subject: [PATCH] checkpatch: skip macros when finding missing switch/case break
Date: Wed, 29 Jul 2020 20:59:11 +0800	[thread overview]
Message-ID: <20200729125911.47318-1-cambda@linux.alibaba.com> (raw)

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@linux.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


             reply	other threads:[~2020-07-29 12:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 12:59 Cambda Zhu [this message]
2020-07-31 18:05 ` Joe Perches
2020-08-01  5:03 Cambda Zhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200729125911.47318-1-cambda@linux.alibaba.com \
    --to=cambda@linux.alibaba.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®