[PATCH 04/17] mtd: partitions: Add error check

Sascha Hauer s.hauer at pengutronix.de
Thu Feb 12 00:54:21 PST 2015


add_mtd_device can fail. Add an error check and bail out properly.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/mtd/partition.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/partition.c b/drivers/mtd/partition.c
index 033a7d2..c514d4b 100644
--- a/drivers/mtd/partition.c
+++ b/drivers/mtd/partition.c
@@ -108,6 +108,7 @@ struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset,
 		uint64_t size, unsigned long flags, const char *name)
 {
 	struct mtd_info *part;
+	int ret;
 
 	part = xzalloc(sizeof(*part));
 
@@ -168,9 +169,17 @@ struct mtd_info *mtd_add_partition(struct mtd_info *mtd, off_t offset,
 	if (!strncmp(mtd->cdev.name, name, strlen(mtd->cdev.name)))
 		part->cdev.partname = xstrdup(name + strlen(mtd->cdev.name) + 1);
 
-	add_mtd_device(part, part->name, DEVICE_ID_SINGLE);
+	ret = add_mtd_device(part, part->name, DEVICE_ID_SINGLE);
+	if (ret)
+		goto err;
 
 	return part;
+err:
+	free(part->cdev.partname);
+	free(part->name);
+	free(part);
+
+	return ERR_PTR(ret);
 }
 
 int mtd_del_partition(struct mtd_info *part)
-- 
2.1.4




More information about the barebox mailing list