From: Markus Elfring Date: Wed, 10 Jun 2026 07:15:52 +0000 (+0200) Subject: mtd: cfi: Use common error handling code in two functions X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=cf4ff717af69cfe2dff8ddb843dce36205cb3c40;p=thirdparty%2Fkernel%2Flinux.git mtd: cfi: Use common error handling code in two functions Use additional labels so that a bit of exception handling can be better reused at the end of two function implementations. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring Signed-off-by: Miquel Raynal --- diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index a38aceb6612d0..517db2f2707f4 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c @@ -661,8 +661,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) extp->MajorVersion, extp->MinorVersion, extp->MajorVersion, extp->MinorVersion); kfree(extp); - kfree(mtd); - return NULL; + goto free_mtd; } printk(KERN_INFO " Amd/Fujitsu Extended Query version %c.%c.\n", @@ -714,10 +713,8 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) } cfi_fixup(mtd, cfi_nopri_fixup_table); - if (!cfi->addr_unlock1 || !cfi->addr_unlock2) { - kfree(mtd); - return NULL; - } + if (!cfi->addr_unlock1 || !cfi->addr_unlock2) + goto free_mtd; } /* CFI mode */ else if (cfi->cfi_mode == CFI_MODE_JEDEC) { @@ -755,6 +752,10 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) map->fldrv = &cfi_amdstd_chipdrv; return cfi_amdstd_setup(mtd); + +free_mtd: + kfree(mtd); + return NULL; } struct mtd_info *cfi_cmdset_0006(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002"))); struct mtd_info *cfi_cmdset_0701(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002"))); diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c index 6b5727eaae690..593ac65a7e2f0 100644 --- a/drivers/mtd/chips/cfi_cmdset_0020.c +++ b/drivers/mtd/chips/cfi_cmdset_0020.c @@ -174,11 +174,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) mtd = kzalloc_obj(*mtd); //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips); - - if (!mtd) { - kfree(cfi->cmdset_priv); - return NULL; - } + if (!mtd) + goto free_cmdset_priv; mtd->priv = map; mtd->type = MTD_NORFLASH; @@ -187,11 +184,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; mtd->eraseregions = kmalloc_objs(struct mtd_erase_region_info, mtd->numeraseregions); - if (!mtd->eraseregions) { - kfree(cfi->cmdset_priv); - kfree(mtd); - return NULL; - } + if (!mtd->eraseregions) + goto free_mtd; for (i=0; icfiq->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; inumeraseregions;i++){ @@ -242,6 +234,12 @@ 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_cmdset_priv: + kfree(cfi->cmdset_priv); + return NULL; }