[PATCH] driver core: fix memory leak in physical location error path
From: Johan Hovold
Date: Mon Nov 02 2026 - 03:36:56 EST
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")
Closes: https://sashiko.dev/#/bug/linux-b178c32c-f23b-48fd-9463-70f321f2d91e
Cc: stable@xxxxxxxxxxxxxxx # 5.19
Cc: Won Chung <wonchung@xxxxxxxxxx>
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/base/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index cbe05197d4a0..bf97b06337a1 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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);
--
2.55.0