Skip to contentSkip to conversation

checkpatch: detect leading * in NULL comparison check

PATCH In review S. Gilles 2 participants 3 messages Dec 13, 2015 Checkpatch

lore
Share & tools
lore

S. Gilles

author
#0 lore raw

PATCH 1/1 checkpatch: detect leading * in NULL comparison check

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.

---

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(-)
scripts/checkpatch.pl +3 -3
index d4960f7..e549d59 100755
@@ -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) {
Signature · 1 line
2.6.3
maintainer
#1 lore raw
Quoted 6 lines · 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) {

Quoted 7 lines

by checking for leading * characters in the comparison value.

---

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.

author
#2 lore raw
Quoted 12 lines · Joe Perches
Quoted 11 lines · 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.

---

Quoted 8 lines
Quoted 2 lines

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.

Signature · 1 line
S. Gilles