Skip to contentSkip to conversation

driver core: fix memory leak in physical location error path

PATCH Applied Johan Hovold 2 participants 2 messages Nov 2 – Nov 6

Subsystems (2)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/1 driver core: fix memory leak in physical location error path

Make sure to free the physical location memory also in the unlikely event that creating its sysfs attributes fails during probe.

Fixes 6423d2951087 ("driver core: Add sysfs support for physical location of a device")
Cc Won Chung <[email protected]>
---
 drivers/base/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/base/core.c +3 -2
index cbe05197d4a0..bf97b06337a1 100644
@@ -3011,12 +3011,13 @@ static int device_add_attrs(struct device *dev)
 		error = device_add_group(dev,
 			&dev_attr_physical_location_group);
 		if (error)
-			goto err_remove_dev_removable;
+			goto err_free_physical_location;
 	}
 
 	return 0;
 
- err_remove_dev_removable:
+ err_free_physical_location:
+	kfree(dev->physical_location);
 	device_remove_file(dev, &dev_attr_removable);
  err_remove_dev_waiting_for_supplier:
 	device_remove_file(dev, &dev_attr_waiting_for_supplier);
Signature · 1 line
2.55.0
maintainer Applied
#1 lore raw
Quoted 1 line · Johan Hovold

[PATCH] driver core: fix memory leak in physical location error path

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] driver core: fix memory leak in physical location error path

      commit: c890943b295b

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.