History

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.

Markus Elfring committed 5 months ago

Commit cf4ff711 parent 4fe97a52 files · +18 −19Browse files

Unified · Split

2 files
  1. drivers/mtd/chips/cfi_cmdset_0002.c +7 −6
  2. drivers/mtd/chips/cfi_cmdset_0020.c +11 −13
drivers/mtd/chips/cfi_cmdset_0002.c+7−6
@@ -661,8 +661,7 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) · 660 unmodified lines
661661 extp->MajorVersion, extp->MinorVersion,
662662 extp->MajorVersion, extp->MinorVersion);
663663 kfree(extp);
664− kfree(mtd);
665− return NULL;
664+ goto free_mtd;
666665 }
667666
668667 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
714713 }
715714 cfi_fixup(mtd, cfi_nopri_fixup_table);
716715
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;
721718
722719 } /* CFI mode */
723720 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
755752 map->fldrv = &cfi_amdstd_chipdrv;
756753
757754 return cfi_amdstd_setup(mtd);
755+
756+free_mtd:
757+ kfree(mtd);
758+ return NULL;
758759 }
759760 struct mtd_info *cfi_cmdset_0006(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002")));
760761 struct mtd_info *cfi_cmdset_0701(struct map_info *map, int primary) __attribute__((alias("cfi_cmdset_0002")));
drivers/mtd/chips/cfi_cmdset_0020.c+11−13
@@ -174,11 +174,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 173 unmodified lines
174174
175175 mtd = kzalloc_obj(*mtd);
176176 //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;
182179
183180 mtd->priv = map;
184181 mtd->type = MTD_NORFLASH;
@@ -187,11 +184,8 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 2 unmodified lines
187184 mtd->numeraseregions = cfi->cfiq->NumEraseRegions * cfi->numchips;
188185 mtd->eraseregions = kmalloc_objs(struct mtd_erase_region_info,
189186 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;
195189
196190 for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
197191 unsigned long ernum, ersize;
@@ -213,9 +207,7 @@ static struct mtd_info *cfi_staa_setup(struct map_info *map) · 15 unmodified lines
213207 /* Argh */
214208 printk(KERN_WARNING "Sum of regions (%lx) != total size of set of interleaved chips (%lx)\n", offset, devsize);
215209 kfree(mtd->eraseregions);
216− kfree(cfi->cmdset_priv);
217− kfree(mtd);
218− return NULL;
210+ goto free_mtd;
219211 }
220212
221213 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
242234 __module_get(THIS_MODULE);
243235 mtd->name = map->name;
244236 return mtd;
237+
238+free_mtd:
239+ kfree(mtd);
240+free_cmdset_priv:
241+ kfree(cfi->cmdset_priv);
242+ return NULL;
245243 }
246244
247245

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t