Skip to contentSkip to conversation

PNP: fix name memory leak in pnp_alloc_dev()

PATCH Superseded Yang Yingliang 2 participants 2 messages Nov 10, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PNP: fix name memory leak in pnp_alloc_dev()

Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array"), the name of device is allocated dynamically, it need be freed in the error path.

Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
---
 drivers/pnp/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pnp/core.c +1 -0
index 4df5aa6a309c..bb3976566822 100644
@@ -152,6 +152,7 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
 
 	dev_id = pnp_add_id(dev, pnpid);
 	if (!dev_id) {
+		kfree_const(dev->dev.kobj.name);
 		kfree(dev);
 		return NULL;
 	}
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Yang Yingliang

Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's

After

Quoted 14 lines

bus_id string array"), the name of device is allocated dynamically, it need be freed in the error path.

Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
---
 drivers/pnp/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pnp/core.c +0 -0
index 4df5aa6a309c..bb3976566822 100644

drivers/pnp/core.c struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, · line 155

Quoted 4 lines
drivers/pnp/core.c +1 -0
@@ -152,6 +152,7 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
 
        dev_id = pnp_add_id(dev, pnpid);
        if (!dev_id) {
+               kfree_const(dev->dev.kobj.name);

Would be better to move the dev_set_name() invocation after this if () unstead.

Quoted 4 lines
drivers/pnp/core.c +0 -1
                kfree(dev);
                return NULL;
        }
--