summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Fan <[email protected]>2026-07-03 17:11:27 +0800
committerTom Rini <[email protected]>2026-07-16 12:03:05 -0600
commite1f345abf4c0df94ef6c5eca400a440c16b47d81 (patch)
treeac61a6905fcf985e3da914531cb1385c2183c615
parent0af2ed57a3e9c34775602ea70d5c9829c4e830c6 (diff)
dm: core: free old name in device_set_name to prevent leak
If device_set_name is called on a device that already has DM_FLAG_NAME_ALLOCED set, the old dynamically-allocated name is leaked. Free it before assigning the new name. See: drivers/net/mdio_gpio.c:mdio_gpio_bind(). There is device_set_name() here, however dm_mdio_post_bind() will also call device_set_name() if "device-name" exists. Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Simon Glass <[email protected]>
-rw-r--r--drivers/core/device.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index d365204ba11..6024534ff93 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -1147,6 +1147,8 @@ int device_set_name(struct udevice *dev, const char *name)
name = strdup(name);
if (!name)
return -ENOMEM;
+ if (dev_get_flags(dev) & DM_FLAG_NAME_ALLOCED)
+ free((char *)dev->name);
dev->name = name;
device_set_name_alloced(dev);