From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
linux-kernel@vger.kernel.org
Subject: checkpatch: comparisons with a constant on the left
Date: Fri, 11 Oct 2019 10:52:25 +0900 [thread overview]
Message-ID: <20191011015225.GA27495@jagdpanzerIV> (raw)
Hi Joe,
I noticed that this code
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
triggers checkpatch's warning:
"WARNING: Comparisons should place the constant on
the right side of the test"
Both LINUX_VERSION_CODE and KERNEL_VERSION are constants, so
I'm wondering if it's worth it to improve that check a tiny
bit.
E.g. something utterly trivial:
---
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index cf7543a9d1b2..8a1964c3d9a5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4855,6 +4855,7 @@ sub process {
my $to = $4;
my $newcomp = $comp;
if ($lead !~ /(?:$Operators|\.)\s*$/ &&
+ $to !~ /^KERNEL_VERSION.*/ &&
$to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
WARN("CONSTANT_COMPARISON",
"Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
---
I'm sure you'll have a better idea.
-ss
next reply other threads:[~2019-10-11 1:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-11 1:52 Sergey Senozhatsky [this message]
2019-10-11 3:23 ` Joe Perches
2019-10-20 7:30 ` Sergey Senozhatsky
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=20191011015225.GA27495@jagdpanzerIV \
--to=sergey.senozhatsky.work@gmail.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sergey.senozhatsky@gmail.com \
/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®