From: Peng Fan <[email protected]> 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]> --- 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); -- 2.51.0

