From e1f345abf4c0df94ef6c5eca400a440c16b47d81 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Fri, 3 Jul 2026 17:11:27 +0800 Subject: 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 Reviewed-by: Simon Glass --- drivers/core/device.c | 2 ++ 1 file changed, 2 insertions(+) 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); -- cgit v1.3.1