From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752609AbbH0HPG (ORCPT ); Thu, 27 Aug 2015 03:15:06 -0400 Received: from zimbra1.kalray.eu ([92.103.151.219]:33996 "EHLO zimbra1.kalray.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751061AbbH0HPE (ORCPT ); Thu, 27 Aug 2015 03:15:04 -0400 X-Greylist: delayed 354 seconds by postgrey-1.27 at vger.kernel.org; Thu, 27 Aug 2015 03:15:04 EDT Date: Thu, 27 Aug 2015 09:09:07 +0200 (CEST) From: Nicolas Morey Chaisemartin To: Joe Perches Cc: Viresh Kumar , Andrew Morton , Dan Carpenter , Greg KH , LKML , Mike Holmes Message-ID: <975828790.5069815.1440659347329.JavaMail.zimbra@kalray.eu> In-Reply-To: <1440644737.11525.64.camel@perches.com> References: <1415905054.4223.7.camel@perches.com> <1440644737.11525.64.camel@perches.com> Subject: Re: [PATCH] checkpatch: add --strict "pointer comparison to NULL" test MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.0.8.66] X-Mailer: Zimbra 8.0.4_GA_5737 (ZimbraWebClient - FF42 (Win)/8.0.4_GA_5737) Thread-Topic: checkpatch: add --strict "pointer comparison to NULL" test Thread-Index: ZCyUBZGexuJplzyiNIHFHeyGk1QcEg== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Original Message ----- > From: "Joe Perches" > To: "Viresh Kumar" > Cc: "Andrew Morton" , "Dan Carpenter" , "Greg KH" > , "LKML" , "Mike Holmes" , > 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