Skip to contentSkip to conversation

mtd: nand: sunxi: prevent a small memory leak

PATCH Applied Dan Carpenter 2 participants 2 messages Jun 24, 2016 – Jul 4, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: nand: sunxi: prevent a small memory leak

I moved the sanity check on ecc->size before the allocation so that we don't leak memory on error.

Fixes 05af074a4b73 ('mtd: nand: sunxi: check ecc->size values')
drivers/mtd/nand/sunxi_nand.c +3 -3
index f582fe4..9f4e1c7 100644
@@ -1812,13 +1812,13 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
 	int ret;
 	int i;
 
+	if (ecc->size != 512 && ecc->size != 1024)
+		return -EINVAL;
+
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
-	if (ecc->size != 512 && ecc->size != 1024)
-		return -EINVAL;
-
 	/* Prefer 1k ECC chunk over 512 ones */
 	if (ecc->size = 512 && mtd->writesize > 512) {
 		ecc->size = 1024;
#1 lore raw
Quoted 5 lines · On Fri, 24 Jun 2016 15:24:03 +0300 Dan Carpenter <[email protected]>…

I moved the sanity check on ecc->size before the allocation so that we don't leak memory on error.

Fixes 05af074a4b73 ('mtd: nand: sunxi: check ecc->size values')

Applied.

Thanks,

Boris

Quoted 22 lines
drivers/mtd/nand/sunxi_nand.c +3 -3
index f582fe4..9f4e1c7 100644
@@ -1812,13 +1812,13 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
 	int ret;
 	int i;
 
+	if (ecc->size != 512 && ecc->size != 1024)
+		return -EINVAL;
+
 	data = kzalloc(sizeof(*data), GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
 
-	if (ecc->size != 512 && ecc->size != 1024)
-		return -EINVAL;
-
 	/* Prefer 1k ECC chunk over 512 ones */
 	if (ecc->size = 512 && mtd->writesize > 512) {
 		ecc->size = 1024;