[PATCH 17/18] mtd-cfi_cmdset_0020: Use common error handling code in cfi_staa_setup()
SF Markus Elfring
elfring at users.sourceforge.net
Wed Jan 11 12:52:27 PST 2017
From: Markus Elfring <elfring at users.sourceforge.net>
Date: Wed, 11 Jan 2017 20:02:40 +0100
Add jump targets so that a bit of exception handling can be better reused
at the end of this function.
Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
---
drivers/mtd/chips/cfi_cmdset_0020.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 9cd7b1c6faba..60de9d58dcc6 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -173,11 +173,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
//printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips);
-
- if (!mtd) {
- kfree(cfi->cmdset_priv);
- return NULL;
- }
+ if (!mtd)
+ goto free_priv;
mtd->priv = map;
mtd->type = MTD_NORFLASH;
@@ -187,11 +184,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
mtd->eraseregions = kmalloc_array(mtd->numeraseregions,
sizeof(*mtd->eraseregions),
GFP_KERNEL);
- if (!mtd->eraseregions) {
- kfree(cfi->cmdset_priv);
- kfree(mtd);
- return NULL;
- }
+ if (!mtd->eraseregions)
+ goto free_mtd;
for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
unsigned long ernum, ersize;
@@ -213,9 +207,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
/* Argh */
printk(KERN_WARNING "Sum of regions (%lx) != total size of set of interleaved chips (%lx)\n", offset, devsize);
kfree(mtd->eraseregions);
- kfree(cfi->cmdset_priv);
- kfree(mtd);
- return NULL;
+ goto free_mtd;
}
for (i=0; i<mtd->numeraseregions;i++){
@@ -242,6 +234,11 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map)
__module_get(THIS_MODULE);
mtd->name = map->name;
return mtd;
+free_mtd:
+ kfree(mtd);
+free_priv:
+ kfree(cfi->cmdset_priv);
+ return NULL;
}
--
2.11.0
More information about the linux-mtd
mailing list