Patchwork mtd: fix error path in physmap.c

login
register
mail settings
Submitter hartleys
Date Oct. 21, 2009, 1:09 a.m.
Message ID <BD79186B4FD85F4B8E60E381CAEE190901E24920@mi8nycmail19.Mi8.com>
Download mbox | patch
Permalink /patch/36486/
State New
Headers show

Comments

hartleys - Oct. 21, 2009, 1:09 a.m.
During the physmap probe, add_mtd_partitions() and add_mtd_device()
can both return an error.  Add an error path to handle this.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: David Woodhouse <dwmw2@infradead.org>

---

Patch

diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 3f13a96..966b25d 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -169,24 +169,28 @@  static int physmap_flash_probe(struct platform_device *dev)
 		goto err_out;
 
 #ifdef CONFIG_MTD_PARTITIONS
-	err = parse_mtd_partitions(info->cmtd, part_probe_types,
-				&info->parts, 0);
-	if (err > 0) {
-		add_mtd_partitions(info->cmtd, info->parts, err);
-		info->nr_parts = err;
-		return 0;
+	info->nr_parts = parse_mtd_partitions(info->cmtd, part_probe_types,
+					      &info->parts, 0);
+	if (info->nr_parts > 0) {
+		err = add_mtd_partitions(info->cmtd, info->parts,
+					 info->nr_parts);
+		goto out;
 	}
 
 	if (physmap_data->nr_parts) {
 		printk(KERN_NOTICE "Using physmap partition information\n");
-		add_mtd_partitions(info->cmtd, physmap_data->parts,
-				   physmap_data->nr_parts);
-		return 0;
+		err = add_mtd_partitions(info->cmtd, physmap_data->parts,
+					 physmap_data->nr_parts);
+		goto out;
 	}
 #endif
 
-	add_mtd_device(info->cmtd);
-	return 0;
+	if (add_mtd_device(info->cmtd) == 1)
+		err = -ENODEV;
+
+out:
+	if (!err)
+		return 0;
 
 err_out:
 	physmap_flash_remove(dev);