diff mbox

[upstream] mtd/ifc: fix ifc driver memory release issue

Message ID CAN8TOE-fpTYj5Z5VW=MbH6epK9Ymc+=uQkh7V6=k=76_DjouPA@mail.gmail.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Brian Norris March 29, 2013, 4:28 a.m. UTC
On Wed, Mar 27, 2013 at 5:25 AM, Roy Zang <tie-fei.zang@freescale.com> wrote:
> memory is allocated by devm_kzalloc, so release it using
> devm_kfree() instead kfree();

You are correct that it should not be freed with kfree(). But the
correct solution is that it does not need to be freed (explicitly) at
all. That's the whole point of the managed allocators (i.e.,
devm_kzalloc()). Try this patch instead. Totally untested here.

From: Brian Norris <computersforpeace@gmail.com>
Date: Thu, 28 Mar 2013 21:20:27 -0700
Subject: [PATCH] mtd: fsl_ifc_nand: remove incorrect kfree()

The struct fsl_ifc_mtd is allocated with devm_kzalloc, so its memory
is "managed" automatically by the kernel. That is, we do not need to
free it explicitly; it will be freed when the device is removed. And we
*certainly* shouldn't free it with a regular kfree().

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 drivers/mtd/nand/fsl_ifc_nand.c |    1 -
 1 file changed, 1 deletion(-)

Comments

Artem Bityutskiy May 10, 2013, 12:31 p.m. UTC | #1
On Thu, 2013-03-28 at 21:28 -0700, Brian Norris wrote:
> On Wed, Mar 27, 2013 at 5:25 AM, Roy Zang <tie-fei.zang@freescale.com> wrote:
> > memory is allocated by devm_kzalloc, so release it using
> > devm_kfree() instead kfree();
> 
> You are correct that it should not be freed with kfree(). But the
> correct solution is that it does not need to be freed (explicitly) at
> all. That's the whole point of the managed allocators (i.e.,
> devm_kzalloc()). Try this patch instead. Totally untested here.

Pushed to l2-mtd.git, thanks!
diff mbox

Patch

diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index f1f7f12..180bfa7 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -908,7 +908,6 @@  static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)

 	ifc_nand_ctrl->chips[priv->bank] = NULL;
 	dev_set_drvdata(priv->dev, NULL);
-	kfree(priv);

 	return 0;
 }