From: Nicolas Morey Chaisemartin <nmorey@kalray.eu>
To: Joe Perches <joe@perches.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Andrew Morton <akpm@linux-foundation.org>,
Dan Carpenter <dan.carpenter@oracle.com>,
Greg KH <gregkh@linuxfoundation.org>,
LKML <linux-kernel@vger.kernel.org>,
Mike Holmes <mike.holmes@linaro.org>
Subject: Re: [PATCH] checkpatch: add --strict "pointer comparison to NULL" test
Date: Thu, 27 Aug 2015 09:09:07 +0200 (CEST) [thread overview]
Message-ID: <975828790.5069815.1440659347329.JavaMail.zimbra@kalray.eu> (raw)
In-Reply-To: <1440644737.11525.64.camel@perches.com>
----- Original Message -----
> From: "Joe Perches" <joe@perches.com>
> To: "Viresh Kumar" <viresh.kumar@linaro.org>
> Cc: "Andrew Morton" <akpm@linux-foundation.org>, "Dan Carpenter" <dan.carpenter@oracle.com>, "Greg KH"
> <gregkh@linuxfoundation.org>, "LKML" <linux-kernel@vger.kernel.org>, "Mike Holmes" <mike.holmes@linaro.org>,
> nmorey@kalray.eu
> Sent: Thursday, 27 August, 2015 5:05:37 AM
> Subject: Re: [PATCH] checkpatch: add --strict "pointer comparison to NULL" test
>
> On Thu, 2015-08-27 at 07:49 +0530, Viresh Kumar wrote:
> > Few colleagues asked me why isn't checkpatch warning for (NULL == ptr)
> > or (NULL != ptr) checks, as it warns for (ptr == NULL) and (ptr != NULL).
> >
> > Did you miss it? or was it intentional ?
>
> I didn't miss it.
>
> NULL == foo is relatively unusual and not really worth the
> bother.
>
> And because most likely, "CONST test variable" checks like
> NULL != foo
> and
> 0 < bar
>
> should probably be a separate test.
>
> Something like:
> ---
> scripts/checkpatch.pl | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index e14dcdb..457ddef 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -4231,6 +4231,29 @@ sub process {
> }
> }
>
> +# comparisons with a constant on the left
> + if ($^V && $^V ge 5.10.0 &&
> + $line =~ /\b($Constant|[A-Z_]+)\s*($Compare)\s*($LvalOrFunc)/) {
> + my $const = $1;
> + my $comp = $2;
> + my $to = $3;
> + my $newcomp = $comp;
> + if (WARN("CONSTANT_COMPARISON",
> + "Comparisons should place the constant on the right side of the test\n"
> . $herecurr) &&
> + $fix) {
> + if ($comp eq "<") {
> + $newcomp = ">=";
> + } elsif ($comp eq "<=") {
> + $newcomp = ">";
> + } elsif ($comp eq ">") {
> + $newcomp = "<=";
> + } elsif ($comp eq ">=") {
> + $newcomp = "<";
> + }
I like the concept but are you sure about this? I think the "=" should be added or removed. If a < b, b > a, not b >= a.
Nicolas
next prev parent reply other threads:[~2015-08-27 7:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-13 18:57 Joe Perches
2015-08-27 2:19 ` Viresh Kumar
2015-08-27 3:05 ` Joe Perches
2015-08-27 7:09 ` Nicolas Morey Chaisemartin [this message]
2015-08-27 7:22 ` Joe Perches
2015-08-27 17:33 ` [PATCH] checkpatch: add constant comparison on left side test Joe Perches
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=975828790.5069815.1440659347329.JavaMail.zimbra@kalray.eu \
--to=nmorey@kalray.eu \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.holmes@linaro.org \
--cc=viresh.kumar@linaro.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
Powered by JetHome