mtd/drivers/mtd/chips cfi_cmdset_0001.c,1.106,1.107

spse at infradead.org spse at infradead.org
Sun Nov 17 08:05:05 EST 2002


Update of /home/cvs/mtd/drivers/mtd/chips
In directory phoenix.infradead.org:/tmp/cvs-serv8605

Modified Files:
	cfi_cmdset_0001.c 
Log Message:



cfi_intelext_setup(): fix up memleaks in the init failpath

cfi_intelext_destroy(): free cfi->cmdset_priv and mtd->eraseregions

Index: cfi_cmdset_0001.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/chips/cfi_cmdset_0001.c,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- cfi_cmdset_0001.c	6 Nov 2002 16:13:57 -0000	1.106
+++ cfi_cmdset_0001.c	17 Nov 2002 13:05:01 -0000	1.107
@@ -201,8 +201,7 @@
 
 	if (!mtd) {
 		printk(KERN_ERR "Failed to allocate memory for MTD device\n");
-		kfree(cfi->cmdset_priv);
-		return NULL;
+		goto setup_err;
 	}
 
 	memset(mtd, 0, sizeof(*mtd));
@@ -215,8 +214,7 @@
 			* mtd->numeraseregions, GFP_KERNEL);
 	if (!mtd->eraseregions) { 
 		printk(KERN_ERR "Failed to allocate memory for MTD erase region info\n");
-		kfree(cfi->cmdset_priv);
-		return NULL;
+		goto setup_err;
 	}
 	
 	for (i=0; i<cfi->cfiq->NumEraseRegions; i++) {
@@ -238,9 +236,7 @@
 	if (offset != devsize) {
 		/* 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);
-		return NULL;
+		goto setup_err;
 	}
 
 	for (i=0; i<mtd->numeraseregions;i++){
@@ -282,6 +278,16 @@
 	MOD_INC_USE_COUNT;
 	mtd->name = map->name;
 	return mtd;
+
+ setup_err:
+	if(mtd) {
+		if(mtd->eraseregions)
+			kfree(mtd->eraseregions);
+		kfree(mtd);
+	}
+	kfree(cfi->cmdset_priv);
+	kfree(cfi->cfiq);
+	return NULL;
 }
 
 static int do_point_onechip (struct map_info *map,  struct flchip *chip, loff_t adr, size_t len)
@@ -1829,7 +1835,9 @@
 	struct map_info *map = mtd->priv;
 	struct cfi_private *cfi = map->fldrv_priv;
 	kfree(cfi->cmdset_priv);
+	kfree(cfi->cfiq);
 	kfree(cfi);
+	kfree(mtd->eraseregions);
 }
 
 static char im_name_1[]="cfi_cmdset_0001";





More information about the linux-mtd-cvs mailing list