[U-Boot] [PATCH v2 03/24] dm: blk: Free the block device name when unbound

Simon Glass sjg at chromium.org
Sun May 1 21:52:24 CEST 2016


Mark the device name as allocated so that it will be freed correctly when the
device is unbound.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

Changes in v2: None

 drivers/block/blk-uclass.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index f67f9b9..a37239e 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -468,14 +468,22 @@ int blk_create_devicef(struct udevice *parent, const char *drv_name,
 		       lbaint_t size, struct udevice **devp)
 {
 	char dev_name[30], *str;
+	int ret;
 
 	snprintf(dev_name, sizeof(dev_name), "%s.%s", parent->name, name);
 	str = strdup(dev_name);
 	if (!str)
 		return -ENOMEM;
 
-	return blk_create_device(parent, drv_name, str, if_type, devnum,
-				 blksz, size, devp);
+	ret = blk_create_device(parent, drv_name, str, if_type, devnum,
+				blksz, size, devp);
+	if (ret) {
+		free(str);
+		return ret;
+	}
+	device_set_name_alloced(*devp);
+
+	return ret;
 }
 
 int blk_unbind_all(int if_type)
-- 
2.8.0.rc3.226.g39d4020



More information about the U-Boot mailing list