Skip to contentSkip to conversation

drivers/elbc:Memory leak fix

PATCH In review Raghav Dogra 4 participants 5 messages May 20, 2015 – May 24, 2015

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

PATCH 1/1 drivers/elbc:Memory leak fix

Freeing allocated memory to priv before returning
from the function

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
index e85832d..bbf1f39 100644
@@ -679,6 +679,7 @@ static int fsl_elbc_chip_init(int devnum, u8 *addr)
 	if (priv->bank >= MAX_BANKS) {
 		printf("fsl_elbc_nand: address did not match any "
 		       "chip selects\n");
+		kfree((void *)priv);
 		return -ENODEV;
 	}
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 13 lines · Raghav Dogra

Freeing allocated memory to priv before returning
from the function

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/fsl_elbc_nand.c +0 -0
index e85832d..bbf1f39 100644

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(int devnum, u8 *addr) · line 684

Quoted 6 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
@@ -679,6 +679,7 @@ static int fsl_elbc_chip_init(int devnum, u8 *addr)
 	if (priv->bank >= MAX_BANKS) {
 		printf("fsl_elbc_nand: address did not match any "
 		       "chip selects\n");
+		kfree((void *)priv);
 		return -ENODEV;
 	}

Cast is unnecessary; I'll remove when applying.

-Scott

#2 lore raw
Quoted 16 lines

-----Original Message-----
From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Scott Wood
Sent: Saturday, May 23, 2015 1:57 AM
To: Dogra Raghav-B46184
Cc: u-boot at lists.denx.de; Sun York-R58495
Subject: Re: [U-Boot] drivers/elbc:Memory leak fix

Quoted 7 lines · Raghav Dogra

Freeing allocated memory to priv before returning from the function

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(int devnum, u8 *addr) · line 684

Quoted 12 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
index e85832d..bbf1f39 100644
@@ -679,6 +679,7 @@ static int fsl_elbc_chip_init(int devnum, u8 *addr)
 	if (priv->bank >= MAX_BANKS) {
 		printf("fsl_elbc_nand: address did not match any "
 		       "chip selects\n");
+		kfree((void *)priv);
 		return -ENODEV;
 	}

Cast is unnecessary; I'll remove when applying.

It is required as kfree declaration need void pointer.
It is not getting catch during GCC build. But during static analysis using Klockwork, this is shown as error.

I will suggest to have this patch as it is. It is good practice to pass pointer in the desired format to called function.

--prabhakar

#3 lore raw
Quoted 32 lines · On Fri, 2015-05-22 at 21:55 -0500, Kushwaha Prabhakar-B32579 wrote:
Quoted 16 lines

-----Original Message-----
From: U-Boot [mailto:u-boot-bounces at lists.denx.de] On Behalf Of Scott Wood
Sent: Saturday, May 23, 2015 1:57 AM
To: Dogra Raghav-B46184
Cc: u-boot at lists.denx.de; Sun York-R58495
Subject: Re: [U-Boot] drivers/elbc:Memory leak fix

Quoted 7 lines · Raghav Dogra

Freeing allocated memory to priv before returning from the function

---
 drivers/mtd/nand/fsl_elbc_nand.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 15 lines

drivers/mtd/nand/fsl_elbc_nand.c static int fsl_elbc_chip_init(int devnum, u8 *addr) · line 684

Quoted 12 lines
drivers/mtd/nand/fsl_elbc_nand.c +1 -0
index e85832d..bbf1f39 100644
@@ -679,6 +679,7 @@ static int fsl_elbc_chip_init(int devnum, u8 *addr)
 	if (priv->bank >= MAX_BANKS) {
 		printf("fsl_elbc_nand: address did not match any "
 		       "chip selects\n");
+		kfree((void *)priv);
 		return -ENODEV;
 	}

Cast is unnecessary; I'll remove when applying.

Quoted 1 line

It is required as kfree declaration need void pointer.

It is *not* required. Any pointer can be implicitly converted to a void pointer.

Quoted 1 line

It is not getting catch during GCC build. But during static analysis using Klockwork, this is shown as error.

I don't care what Klockwork considers an error. Klockwork does not dictate the project's style guidelines.

Quoted 1 line

I will suggest to have this patch as it is. It is good practice to pass pointer in the desired format to called function.

It is not good practice to cast unnecessarily. Casts bypass the type system and thus should be rare.

-Scott

#4 lore raw
In reply to Kushwaha Prabhakar
Quoted 2 lines · Kushwaha Prabhakar

It is not getting catch during GCC build. But during static analysis using Klockwork, this is shown as error.

Then Klockwork is wrong.