public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: detect leading * in NULL comparison check
@ 2015-12-13 17:59 S. Gilles
  2015-12-13 20:49 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: S. Gilles @ 2015-12-13 17:59 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches, linux-kernel; +Cc: S. Gilles

Prevent checkpatch.pl from emitting messages like

  CHECK: Comparison to NULL could be written "!rx_p"
  #51: FILE: drivers/staging/iio/accel/sca3000_ring.c:51:
  +       if (*rx_p == NULL) {

by checking for leading * characters in the comparison value.

Signed-off-by: S. Gilles <sgilles@math.umd.edu>
---

I've run this through everything in staging/ as a test, it seems to
work okay.

 scripts/checkpatch.pl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d4960f7..e549d59 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4995,10 +4995,10 @@ sub process {
 
 # check for pointer comparisons to NULL
 		if ($^V && $^V ge 5.10.0) {
-			while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
-				my $val = $1;
+			while ($line =~ /([\*]*)\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
+				my $val = $1 . $2;
 				my $equal = "!";
-				$equal = "" if ($4 eq "!=");
+				$equal = "" if ($5 eq "!=");
 				if (CHK("COMPARISON_TO_NULL",
 					"Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
 					    $fix) {
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: detect leading * in NULL comparison check
  2015-12-13 17:59 [PATCH] checkpatch: detect leading * in NULL comparison check S. Gilles
@ 2015-12-13 20:49 ` Joe Perches
  2015-12-13 22:02   ` S. Gilles
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2015-12-13 20:49 UTC (permalink / raw)
  To: S. Gilles, Andy Whitcroft, linux-kernel

On Sun, 2015-12-13 at 12:59 -0500, S. Gilles wrote:
> Prevent checkpatch.pl from emitting messages like
> 
>   CHECK: Comparison to NULL could be written "!rx_p"
>   #51: FILE: drivers/staging/iio/accel/sca3000_ring.c:51:
>   +       if (*rx_p == NULL) {
> 
> by checking for leading * characters in the comparison value.
> 
> Signed-off-by: S. Gilles <sgilles@math.umd.edu>
> ---
> 
> I've run this through everything in staging/ as a test, it seems to
> work okay.

This wouldn't work with

	* foo == NULL;

but there don't seem to be any in the kernel source.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] checkpatch: detect leading * in NULL comparison check
  2015-12-13 20:49 ` Joe Perches
@ 2015-12-13 22:02   ` S. Gilles
  0 siblings, 0 replies; 3+ messages in thread
From: S. Gilles @ 2015-12-13 22:02 UTC (permalink / raw)
  To: Joe Perches; +Cc: S. Gilles, Andy Whitcroft, linux-kernel

On 2015-12-13T12:49:01, Joe Perches wrote:
> On Sun, 2015-12-13 at 12:59 -0500, S. Gilles wrote:
> > Prevent checkpatch.pl from emitting messages like
> > 
> >   CHECK: Comparison to NULL could be written "!rx_p"
> >   #51: FILE: drivers/staging/iio/accel/sca3000_ring.c:51:
> >   +       if (*rx_p == NULL) {
> > 
> > by checking for leading * characters in the comparison value.
> > 
> > Signed-off-by: S. Gilles <sgilles@math.umd.edu>
> > ---
> > 
> > I've run this through everything in staging/ as a test, it seems to
> > work okay.
> 
> This wouldn't work with
> 
> 	* foo == NULL;
> 
> but there don't seem to be any in the kernel source.

Some other stuff like

	*(foo) == NULL

won't be caught as well, but in such false negative cases, other style
conventions would have to be violated anyway. I'm not sure how strong
that argument is.

-- 
S. Gilles

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-13 22:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-13 17:59 [PATCH] checkpatch: detect leading * in NULL comparison check S. Gilles
2015-12-13 20:49 ` Joe Perches
2015-12-13 22:02   ` S. Gilles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox