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.
Unified · Split
| @@ -661,8 +661,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) · 660 unmodified lines | ||
| 661 | 661 | extp->MajorVersion, extp->MinorVersion, |
| 662 | 662 | extp->MajorVersion, extp->MinorVersion); |
| 663 | 663 | kfree(extp); |
| 664 | − kfree(mtd); | |
| 665 | − return NULL; | |
| 664 | + goto free_mtd; | |
| 666 | 665 | } |
| 667 | 666 | |
| 668 | 667 | 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) · 45 unmodified lines | ||
| 714 | 713 | } |
| 715 | 714 | cfi_fixup(mtd, cfi_nopri_fixup_table); |
| 716 | 715 | |
| 717 | − if (!cfi->addr_unlock1 || !cfi->addr_unlock2) { | |
| 718 | − kfree(mtd); | |
| 719 | − return NULL; | |
| 720 | − } | |
| 716 | + if (!cfi->addr_unlock1 || !cfi->addr_unlock2) | |
| 717 | + goto free_mtd; | |
| 721 | 718 | |
| 722 | 719 | } /* CFI mode */ |
| 723 | 720 | else if (cfi->cfi_mode == CFI_MODE_JEDEC) { |
| @@ -755,6 +752,10 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) · 31 unmodified lines | ||
| 755 | 752 | map->fldrv = &cfi_amdstd_chipdrv; |
| 756 | 753 | |
| 757 | 754 | return cfi_amdstd_setup(mtd); |
| 755 | + | |
| 756 | +free_mtd: | |
| 757 | + kfree(mtd); | |
| 758 | + return NULL; | |
| 758 | 759 | } |
| 759 | 760 | struct mtd_info *cfi_cmdset_0006(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002"))); |
| 760 | 761 | struct mtd_info *cfi_cmdset_0701(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002"))); |
| @@ -174,11 +174,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 173 unmodified lines | ||
| 174 | 174 | |
| 175 | 175 | mtd = kzalloc_obj(*mtd); |
| 176 | 176 | //printk(KERN_DEBUG "number of CFI chips: %d\n", cfi->numchips); |
| 177 | − | |
| 178 | − if (!mtd) { | |
| 179 | − kfree(cfi->cmdset_priv); | |
| 180 | − return NULL; | |
| 181 | − } | |
| 177 | + if (!mtd) | |
| 178 | + goto free_cmdset_priv; | |
| 182 | 179 | |
| 183 | 180 | mtd->priv = map; |
| 184 | 181 | mtd->type = MTD_NORFLASH; |
| @@ -187,11 +184,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 2 unmodified lines | ||
| 187 | 184 | mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips; |
| 188 | 185 | mtd->eraseregions = kmalloc_objs(struct mtd_erase_region_info, |
| 189 | 186 | mtd->numeraseregions); |
| 190 | − if (!mtd->eraseregions) { | |
| 191 | − kfree(cfi->cmdset_priv); | |
| 192 | − kfree(mtd); | |
| 193 | − return NULL; | |
| 194 | − } | |
| 187 | + if (!mtd->eraseregions) | |
| 188 | + goto free_mtd; | |
| 195 | 189 | |
| 196 | 190 | for (i=0; i<cfi->cfiq->NumEraseRegions; i++) { |
| 197 | 191 | unsigned long ernum, ersize; |
| @@ -213,9 +207,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 15 unmodified lines | ||
| 213 | 207 | /* Argh */ |
| 214 | 208 | printk(KERN_WARNING "Sum of regions (%lx) != total size of set of interleaved chips (%lx)\n", offset, devsize); |
| 215 | 209 | kfree(mtd->eraseregions); |
| 216 | − kfree(cfi->cmdset_priv); | |
| 217 | − kfree(mtd); | |
| 218 | − return NULL; | |
| 210 | + goto free_mtd; | |
| 219 | 211 | } |
| 220 | 212 | |
| 221 | 213 | for (i=0; i<mtd->numeraseregions;i++){ |
| @@ -242,6 +234,12 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 20 unmodified lines | ||
| 242 | 234 | __module_get(THIS_MODULE); |
| 243 | 235 | mtd->name = map->name; |
| 244 | 236 | return mtd; |
| 237 | + | |
| 238 | +free_mtd: | |
| 239 | + kfree(mtd); | |
| 240 | +free_cmdset_priv: | |
| 241 | + kfree(cfi->cmdset_priv); | |
| 242 | + return NULL; | |
| 245 | 243 | } |
| 246 | 244 | |
| 247 | 245 | |