Skip to contentSkip to conversation

igb: fix compare_const_fl.cocci warnings

PATCH Superseded Julia Lawall 2 participants 4 messages Dec 23, 2015 – Jan 7, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 igb: fix compare_const_fl.cocci warnings

Kernel code typically uses == NULL.

Generated by: scripts/coccinelle/misc/compare_const_fl.cocci

---

Alternatively, consider using !adapter.

 igb_cdev.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/igb/igb_cdev.c +7 -7
@@ -92,7 +92,7 @@ static int igb_bind(struct file *file, v
 
 	adapter = (struct igb_adapter *)file->private_data;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return -ENOENT;
 
 	mmap_size = pci_resource_len(adapter->pdev, 0);
@@ -119,7 +119,7 @@ static long igb_mapring(struct file *fil
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -182,7 +182,7 @@ static long igb_mapbuf(struct file *file
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -246,7 +246,7 @@ static long igb_unmapring(struct file *f
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -310,7 +310,7 @@ static long igb_unmapbuf(struct file *fi
 		return -EFAULT;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -398,7 +398,7 @@ static int igb_close_file(struct inode *
 {
 	struct igb_adapter *adapter = file->private_data;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return 0;
 
 	mutex_lock(&adapter->cdev_mutex);
@@ -434,7 +434,7 @@ static int igb_mmap(struct file *file, s
 	dma_addr_t pgoff = vma->vm_pgoff;
 	dma_addr_t physaddr;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return -ENODEV;
 
 	if (pgoff == 0)
#1 lore raw

PATCH 1/1 igb: fix compare_const_fl.cocci warnings

Actully, there is a more serious problem here, that there are a lot of potential dereferences of invalid pointers, via calls like:

dev_err(&adapter->pdev->dev, "map to unbound device!\n")

julia

Quoted 81 lines · Julia Lawall

Kernel code typically uses == NULL.

Generated by: scripts/coccinelle/misc/compare_const_fl.cocci

---

Alternatively, consider using !adapter.

 igb_cdev.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/igb/igb_cdev.c +7 -7
@@ -92,7 +92,7 @@ static int igb_bind(struct file *file, v
 
 	adapter = (struct igb_adapter *)file->private_data;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return -ENOENT;
 
 	mmap_size = pci_resource_len(adapter->pdev, 0);
@@ -119,7 +119,7 @@ static long igb_mapring(struct file *fil
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -182,7 +182,7 @@ static long igb_mapbuf(struct file *file
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -246,7 +246,7 @@ static long igb_unmapring(struct file *f
 		return -EINVAL;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -310,7 +310,7 @@ static long igb_unmapbuf(struct file *fi
 		return -EFAULT;
 
 	adapter = file->private_data;
-	if (NULL == adapter) {
+	if (adapter == NULL) {
 		dev_err(&adapter->pdev->dev, "map to unbound device!\n");
 		return -ENOENT;
 	}
@@ -398,7 +398,7 @@ static int igb_close_file(struct inode *
 {
 	struct igb_adapter *adapter = file->private_data;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return 0;
 
 	mutex_lock(&adapter->cdev_mutex);
@@ -434,7 +434,7 @@ static int igb_mmap(struct file *file, s
 	dma_addr_t pgoff = vma->vm_pgoff;
 	dma_addr_t physaddr;
 
-	if (NULL == adapter)
+	if (adapter == NULL)
 		return -ENODEV;
 
 	if (pgoff == 0)
#2 lore raw

PATCH 1/1 igb: fix compare_const_fl.cocci warnings

Quoted 6 lines

From: Intel-wired-lan [intel-wired-lan-bounces at lists.osuosl.org] on behalf of Julia Lawall [julia.lawall at lip6.fr]
Sent: Wednesday, December 23, 2015 4:58 AM
To: Gangfeng Huang
Cc: intel-wired-lan at lists.osuosl.org; kbuild-all at 01.org
Subject: Re: [Intel-wired-lan] [PATCH] igb: fix compare_const_fl.cocci warnings

Quoted 6 lines

Actully, there is a more serious problem here, that there are a lot of potential dereferences of invalid pointers, via calls like:

dev_err(&adapter->pdev->dev, "map to unbound device!\n")

julia

I don't see that this patch changes that, it still seems proper to apply this clean up.

Quoted 10 lines · Julia Lawall
Quoted 9 lines

Kernel code typically uses == NULL.

Generated by: scripts/coccinelle/misc/compare_const_fl.cocci

Quoted 6 lines
Quoted 6 lines

---

Alternatively, consider using !adapter.

 igb_cdev.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
#3 lore raw

PATCH 1/1 igb: fix compare_const_fl.cocci warnings

Quoted 6 lines · Aaron F
Quoted 6 lines

From: Intel-wired-lan [intel-wired-lan-bounces at lists.osuosl.org] on behalf of Julia Lawall [julia.lawall at lip6.fr]
Sent: Wednesday, December 23, 2015 4:58 AM
To: Gangfeng Huang
Cc: intel-wired-lan at lists.osuosl.org; kbuild-all at 01.org
Subject: Re: [Intel-wired-lan] [PATCH] igb: fix compare_const_fl.cocci warnings

Quoted 8 lines
Quoted 6 lines

Actully, there is a more serious problem here, that there are a lot of potential dereferences of invalid pointers, via calls like:

dev_err(&adapter->pdev->dev, "map to unbound device!\n")

julia

I don't see that this patch changes that, it still seems proper to apply this clean up.

No, the patch just does what the rule says, which is move the NULL to the other side.

julia

Quoted 19 lines
Quoted 11 lines · Julia Lawall
Quoted 9 lines

Kernel code typically uses == NULL.

Generated by: scripts/coccinelle/misc/compare_const_fl.cocci

Quoted 6 lines
Quoted 6 lines

---

Alternatively, consider using !adapter.

 igb_cdev.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)