summaryrefslogtreecommitdiff
path: root/include/dm
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 /include/dm
parent72a85c0d2dfe965c831670f06d3803aaad7bb5b1 (diff)
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 'include/dm')
-rw-r--r--include/dm/device.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/dm/device.h b/include/dm/device.h
index 8970fc015c7..e9a8ec72c90 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -41,6 +41,9 @@ struct driver_info;
/* Device is bound */
#define DM_FLAG_BOUND (1 << 6)
+/* Device name is allocated and should be freed on unbind() */
+#define DM_NAME_ALLOCED (1 << 7)
+
/**
* struct udevice - An instance of a driver
*
@@ -523,6 +526,9 @@ bool device_is_last_sibling(struct udevice *dev);
* this is unnecessary but for probed devices which don't get a useful name
* this function can be helpful.
*
+ * The name is allocated and will be freed automatically when the device is
+ * unbound.
+ *
* @dev: Device to update
* @name: New name (this string is allocated new memory and attached to
* the device)
@@ -532,6 +538,16 @@ bool device_is_last_sibling(struct udevice *dev);
int device_set_name(struct udevice *dev, const char *name);
/**
+ * device_set_name_alloced() - note that a device name is allocated
+ *
+ * This sets the DM_NAME_ALLOCED flag for the device, so that when it is
+ * unbound the name will be freed. This avoids memory leaks.
+ *
+ * @dev: Device to update
+ */
+void device_set_name_alloced(struct udevice *dev);
+
+/**
* device_is_on_pci_bus - Test if a device is on a PCI bus
*
* @dev: device to test