Skip to contentSkip to conversation

PM / devfreq: Remove unnecessary NULL check before kfree

PATCH In review Gustavo A. R. Silva 2 participants 2 messages Nov 12, 2017 Device frequency (devfreq)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: Remove unnecessary NULL check before kfree

NULL check before freeing functions like kfree is not needed.

This issue was detected with the help of Coccinelle.

---
 drivers/devfreq/devfreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/devfreq/devfreq.c +1 -2
index 78fb496..21164a9 100644
@@ -672,8 +672,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
 
 	device_unregister(&devfreq->dev);
 err_dev:
-	if (devfreq)
-		kfree(devfreq);
+	kfree(devfreq);
 err_out:
 	return ERR_PTR(err);
 }
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Hi,

Quoted 15 lines · Gustavo A. R. Silva

NULL check before freeing functions like kfree is not needed.

This issue was detected with the help of Coccinelle.

---
 drivers/devfreq/devfreq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/devfreq/devfreq.c +0 -0
index 78fb496..21164a9 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 678

Quoted 9 lines
drivers/devfreq/devfreq.c +1 -2
@@ -672,8 +672,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
 
 	device_unregister(&devfreq->dev);
 err_dev:
-	if (devfreq)
-		kfree(devfreq);
+	kfree(devfreq);
 err_out:
 	return ERR_PTR(err);
 }

It prevents the memory leak when the registration
of devfreq device is failed. You can check the
detailed reason on patch1[1].

[1] PM / devfreq: Fix memory leak when fail to register device
- https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9e14de1077e9c34f141cf98bdba60cdd5193d962

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics