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