Skip to contentSkip to conversation

MTD/pxa: patch for error return value method of pxa2xx-flash

PATCH New Wan ZongShun 1 participant 1 message Jun 5, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH v2 3/3 MTD/pxa: patch for error return value method of pxa2xx-flash

This patch is to re-implement the 'pxa2xx-flash.c' error return value method of probe() and remove() function,the old return way can arouse the 'info' memory leak risk.

This patch has been reviewed by Eric, according to his advice, I modify some wrong issues of previous patch and resend to maillist.

---
 drivers/mtd/maps/pxa2xx-flash.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/maps/pxa2xx-flash.c +10 -5
index b5bb1a4..e789358 100644
@@ -78,7 +78,8 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
 	if (!info->map.virt) {
 		printk(KERN_WARNING "Failed to ioremap %s\n",
 		       info->map.name);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto fail1;
 	}
 	info->map.cached =
 		ioremap_cached(info->map.phys, info->map.size);
@@ -97,10 +98,8 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
 	info->mtd = do_map_probe(flash->map_name, &info->map);
 
 	if (!info->mtd) {
-		iounmap((void *)info->map.virt);
-		if (info->map.cached)
-			iounmap(info->map.cached);
-		return -EIO;
+		ret = -EIO;
+		goto fail2;
 	}
 	info->mtd->owner = THIS_MODULE;
 
@@ -124,6 +123,12 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, info);
 	return 0;
+
+fail2:	iounmap(info->map.virt);
+	if (info->map.cached)
+		iounmap(info->map.cached);
+fail1:	kfree(info);
+	return ret;
 }
 
 static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
Signature · 1 line
1.6.3.3