All of lore.kernel.org
 help / color / mirror / Atom feed
* [upstream] mtd/ifc: fix ifc driver memory release issue
@ 2013-03-27 12:25 ` Roy Zang
  0 siblings, 0 replies; 6+ messages in thread
From: Roy Zang @ 2013-03-27 12:25 UTC (permalink / raw)
  To: linux-mtd; +Cc: Li Hao, scottwood, linuxppc-dev, dwmw2, Cao Yonghua

memory is allocated by devm_kzalloc, so release it using
devm_kfree() instead kfree();

Signed-off-by: Li Hao <b44421@freescale.com>
Signed-off-by: Cao Yonghua <b43619@freescale.com>
Signed-off-by: Roy Zang <tie-fei.zang@freescale.com>
---
 drivers/mtd/nand/fsl_ifc_nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index f1f7f12..b574ca4 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -908,7 +908,7 @@ 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);
+	devm_kfree(priv->dev, priv);
 
 	return 0;
 }
@@ -974,6 +974,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 		if (!ifc_nand_ctrl) {
 			dev_err(&dev->dev, "failed to allocate memory\n");
 			mutex_unlock(&fsl_ifc_nand_mutex);
+			devm_kfree(&dev->dev, priv);
 			return -ENOMEM;
 		}
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [upstream] mtd/ifc: fix ifc driver memory release issue
@ 2013-03-27 12:25 ` Roy Zang
  0 siblings, 0 replies; 6+ messages in thread
From: Roy Zang @ 2013-03-27 12:25 UTC (permalink / raw)
  To: linux-mtd
  Cc: Roy Zang, galak, Li Hao, scottwood, linuxppc-dev, dwmw2, Cao Yonghua

memory is allocated by devm_kzalloc, so release it using
devm_kfree() instead kfree();

Signed-off-by: Li Hao <b44421@freescale.com>
Signed-off-by: Cao Yonghua <b43619@freescale.com>
Signed-off-by: Roy Zang <tie-fei.zang@freescale.com>
---
 drivers/mtd/nand/fsl_ifc_nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/fsl_ifc_nand.c b/drivers/mtd/nand/fsl_ifc_nand.c
index f1f7f12..b574ca4 100644
--- a/drivers/mtd/nand/fsl_ifc_nand.c
+++ b/drivers/mtd/nand/fsl_ifc_nand.c
@@ -908,7 +908,7 @@ 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);
+	devm_kfree(priv->dev, priv);
 
 	return 0;
 }
@@ -974,6 +974,7 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
 		if (!ifc_nand_ctrl) {
 			dev_err(&dev->dev, "failed to allocate memory\n");
 			mutex_unlock(&fsl_ifc_nand_mutex);
+			devm_kfree(&dev->dev, priv);
 			return -ENOMEM;
 		}
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [upstream] mtd/ifc: fix ifc driver memory release issue
  2013-03-27 12:25 ` Roy Zang
@ 2013-03-29  4:28   ` Brian Norris
  -1 siblings, 0 replies; 6+ messages in thread
From: Brian Norris @ 2013-03-29  4:28 UTC (permalink / raw)
  To: Roy Zang; +Cc: linuxppc-dev, Li Hao, linux-mtd, scottwood, dwmw2, Cao Yonghua

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(-)

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;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [upstream] mtd/ifc: fix ifc driver memory release issue
@ 2013-03-29  4:28   ` Brian Norris
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Norris @ 2013-03-29  4:28 UTC (permalink / raw)
  To: Roy Zang
  Cc: linuxppc-dev, galak, Li Hao, linux-mtd, scottwood, dwmw2, Cao Yonghua

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(-)

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;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [upstream] mtd/ifc: fix ifc driver memory release issue
  2013-03-29  4:28   ` Brian Norris
@ 2013-05-10 12:31     ` Artem Bityutskiy
  -1 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2013-05-10 12:31 UTC (permalink / raw)
  To: Brian Norris
  Cc: Li Hao, linux-mtd, scottwood, linuxppc-dev, dwmw2, Cao Yonghua

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!

-- 
Best Regards,
Artem Bityutskiy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [upstream] mtd/ifc: fix ifc driver memory release issue
@ 2013-05-10 12:31     ` Artem Bityutskiy
  0 siblings, 0 replies; 6+ messages in thread
From: Artem Bityutskiy @ 2013-05-10 12:31 UTC (permalink / raw)
  To: Brian Norris
  Cc: Roy Zang, galak, Li Hao, linux-mtd, scottwood, linuxppc-dev,
	dwmw2, Cao Yonghua

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!

-- 
Best Regards,
Artem Bityutskiy

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-10 12:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-27 12:25 [upstream] mtd/ifc: fix ifc driver memory release issue Roy Zang
2013-03-27 12:25 ` Roy Zang
2013-03-29  4:28 ` Brian Norris
2013-03-29  4:28   ` Brian Norris
2013-05-10 12:31   ` Artem Bityutskiy
2013-05-10 12:31     ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.