Skip to contentSkip to conversation

staging: comedi: drivers: Remove unneeded NULL check before kfree()

PATCH In review Janani Ravichandran 2 participants 3 messages Feb 23, 2016 – Mar 11, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: comedi: drivers: Remove unneeded NULL check before kfree()

Remove NULL check before kfree as it is not needed.

---
 drivers/staging/comedi/drivers/amplc_pci224.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/comedi/drivers/amplc_pci224.c +2 -4
index cac011f..656df1a 100644
@@ -1096,10 +1096,8 @@ static void pci224_detach(struct comedi_device *dev)
 	struct pci224_private *devpriv = dev->private;
 
 	comedi_pci_detach(dev);
-	if (devpriv) {
-		kfree(devpriv->ao_scan_vals);
-		kfree(devpriv->ao_scan_order);
-	}
+	kfree(devpriv->ao_scan_vals);
+	kfree(devpriv->ao_scan_order);
 }
 
 static struct comedi_driver amplc_pci224_driver = {
Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 12 lines · Janani Ravichandran

Remove NULL check before kfree as it is not needed.

---
 drivers/staging/comedi/drivers/amplc_pci224.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/comedi/drivers/amplc_pci224.c +0 -0
index cac011f..656df1a 100644

drivers/staging/comedi/drivers/amplc_pci224.c static void pci224_detach(struct comedi_device *dev) · line 1101

Quoted 10 lines
drivers/staging/comedi/drivers/amplc_pci224.c +2 -4
@@ -1096,10 +1096,8 @@ static void pci224_detach(struct comedi_device *dev)
 	struct pci224_private *devpriv = dev->private;
 
 	comedi_pci_detach(dev);
-	if (devpriv) {
-		kfree(devpriv->ao_scan_vals);
-		kfree(devpriv->ao_scan_order);
-	}
+	kfree(devpriv->ao_scan_vals);
+	kfree(devpriv->ao_scan_order);
 }

Oops, I applied this, but it's obviously wrong. Think about what you just changed here...

I'll go revert it now.

greg k-h

#2 lore raw
Quoted 27 lines · gregkh

Review

Quoted 8 lines · Janani Ravichandran

Remove NULL check before kfree as it is not needed.

Signed-off-by Janani Ravichandran <[email protected] <javascript:>>

---

 drivers/staging/comedi/drivers/amplc_pci224.c | 6 ++---- 
 1 file changed, 2 insertions(+), 4 deletions(-) 
(quoted diff) +0 -0

b/drivers/staging/comedi/drivers/amplc_pci224.c

drivers/staging/comedi/drivers/amplc_pci224.c static void pci224_detach(struct comedi_device

Quoted 4 lines

index cac011f..656df1a 100644

drivers/staging/comedi/drivers/amplc_pci224.c +0 -0
@@ -1096,10 +1096,8 @@ static void pci224_detach(struct comedi_device 

*dev)

drivers/staging/comedi/drivers/amplc_pci224.c static void pci224_detach(struct comedi_device *dev) · line 1101

Quoted 10 lines
drivers/staging/comedi/drivers/amplc_pci224.c +2 -4
         struct pci224_private *devpriv = dev->private; 
 
         comedi_pci_detach(dev); 
-        if (devpriv) { 
-                kfree(devpriv->ao_scan_vals); 
-                kfree(devpriv->ao_scan_order); 
-        } 
+        kfree(devpriv->ao_scan_vals); 
+        kfree(devpriv->ao_scan_order); 
 } 
Quoted 3 lines

Oops, I applied this, but it's obviously wrong. Think about what you just changed here...

Oh yes, it's wrong! devpriv->ao_scan_vals and devpriv->ao_scan_order cannot be accessed if
if(devpriv) is false. Extremely sorry for the carelessness.

Janani.

Quoted 5 lines

I'll go revert it now.

greg k-h