Skip to contentSkip to conversation

mtd: fix INFTL failure handling

PATCH In review Panagiotis Issaris 2 participants 2 messages Mar 6, 2005 – Mar 7, 2005 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: fix INFTL failure handling

Hi,

The INFTL mount code contains a kmalloc() followed by a memset() without handling a possible memory allocation failure.

Signed-off-by <[email protected]>
drivers/mtd/inftlmount.c +6 -0
diff -pruN linux-2.6.11-orig/drivers/mtd/inftlmount.c linux-2.6.11-pi/drivers/mtd/inftlmount.c
@@ -574,6 +574,12 @@ int INFTL_mount(struct INFTLrecord *s)
 
 	/* Temporary buffer to store ANAC numbers. */
 	ANACtable = kmalloc(s->nb_blocks * sizeof(u8), GFP_KERNEL);
+	if (!ANACtable) {
+		printk(KERN_WARNING "INFTL: allocation of ANACtable "
+				"failed (%zd bytes)\n",
+				s->nb_blocks * sizeof(u8));
+		return -ENOMEM;
+	}
 	memset(ANACtable, 0, s->nb_blocks);
 
 	/*
#1 lore raw

Hi Panagiotis,

Quoted 4 lines · Panagiotis Issaris

The INFTL mount code contains a kmalloc() followed by a memset() without handling a possible memory allocation failure.

Signed-off-by <[email protected]>

OK, that looks good.
Dave do you want to take this, or do you want me to submit it?

Regards
Greg

Quoted 17 lines

diff -pruN linux-2.6.11-orig/drivers/mtd/inftlmount.c linux-2.6.11-pi/drivers/mtd/inftlmount.c

drivers/mtd/inftlmount.c +6 -0
@@ -574,6 +574,12 @@ int INFTL_mount(struct INFTLrecord *s)
 
 	/* Temporary buffer to store ANAC numbers. */
 	ANACtable = kmalloc(s->nb_blocks * sizeof(u8), GFP_KERNEL);
+	if (!ANACtable) {
+		printk(KERN_WARNING "INFTL: allocation of ANACtable "
+				"failed (%zd bytes)\n",
+				s->nb_blocks * sizeof(u8));
+		return -ENOMEM;
+	}
 	memset(ANACtable, 0, s->nb_blocks);
 
 	/*
Signature · 5 lines
------------------------------------------------------------------------
Greg Ungerer  --  Chief Software Dude       EMAIL:     [email protected]
SnapGear -- a CyberGuard Company            PHONE:       +61 7 3435 2888
825 Stanley St,                             FAX:         +61 7 3891 3630
Woolloongabba, QLD, 4102, Australia         WEB: http://www.SnapGear.com