]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: cfi: Use common error handling code in two functions
authorMarkus Elfring <elfring@users.sourceforge.net>
Wed, 10 Jun 2026 07:15:52 +0000 (09:15 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Thu, 11 Jun 2026 07:20:50 +0000 (09:20 +0200)
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 <elfring@users.sourceforge.net>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/chips/cfi_cmdset_0002.c
drivers/mtd/chips/cfi_cmdset_0020.c

index a38aceb6612d037536a67a9627fd80aa204b0d3f..517db2f2707f481daf15a90f929f860ec2210436 100644 (file)
@@ -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")));
index 6b5727eaae69022dd9c67be0442310ed3ce3f4ab..593ac65a7e2f08204f672a50be0bf7fffad43021 100644 (file)
@@ -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; 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,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;
 }