summaryrefslogtreecommitdiffstats
path: root/drivers/core/device.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2016-05-01 13:52:23 -0600
committerSimon Glass <sjg@chromium.org>2016-05-17 09:54:43 -0600
commita2040facd23b88082b9b40f0aa9bcfd495eab88e (patch)
treeadc314cd94f8a10e4ac5bb228ae8d98c1b54fead /drivers/core/device.c
parent72a85c0d2dfe965c831670f06d3803aaad7bb5b1 (diff)
downloadtalos-obmc-uboot-a2040facd23b88082b9b40f0aa9bcfd495eab88e.tar.gz
talos-obmc-uboot-a2040facd23b88082b9b40f0aa9bcfd495eab88e.zip
dm: core: Allow device names to be freed automatically
Some devices have a name that is stored in allocated memory. At present there is no mechanism to free this memory when the device is unbound. Add a device flag to track whether a name is allocated and a function to add the flag. Free the memory when the device is unbound. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/core/device.c')
-rw-r--r--drivers/core/device.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 2b12ce7835..5c2dc7021f 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -706,12 +706,18 @@ bool device_is_last_sibling(struct udevice *dev)
return list_is_last(&dev->sibling_node, &parent->child_head);
}
+void device_set_name_alloced(struct udevice *dev)
+{
+ dev->flags |= DM_NAME_ALLOCED;
+}
+
int device_set_name(struct udevice *dev, const char *name)
{
name = strdup(name);
if (!name)
return -ENOMEM;
dev->name = name;
+ device_set_name_alloced(dev);
return 0;
}
OpenPOWER on IntegriCloud