Patchwork PATCH] MTD/maps: correct cleanup in error case

login
register
mail settings
Submitter Benedikt Spranger
Date July 30, 2009, 3:23 p.m.
Message ID <20090730172310.719ad329@ariane.spranger.biz>
Download mbox | patch
Permalink /patch/30389/
State New, archived
Headers show

Comments

Benedikt Spranger - July 30, 2009, 3:23 p.m.
From: Benedikt Spranger <b.spranger@linutronix.de>
Date: Thu, 30 Jul 2009 17:03:51 +0200
Subject: [PATCH] MTD/maps: correct cleanup in error case

fix a copy and paste error introduced by commit 143070e
(mtd: physmap_of: Add multiple regions and concatenation support).

info is needed (via drvdata) and freed in of_flash_remove(), therefore
drvdata should be set right after allocation.

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
---
 drivers/mtd/maps/physmap_of.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
vimal singh - July 31, 2009, 5:52 a.m.
Below patch submitted to fix this along with making sure 'mtd_list' is
not being freed if it has not been allocated:

http://lists.infradead.org/pipermail/linux-mtd/2009-July/026696.html

-vimal


On Thu, Jul 30, 2009 at 8:53 PM, Benedikt
Spranger<b.spranger@linutronix.de> wrote:
> From: Benedikt Spranger <b.spranger@linutronix.de>
> Date: Thu, 30 Jul 2009 17:03:51 +0200
> Subject: [PATCH] MTD/maps: correct cleanup in error case
>
> fix a copy and paste error introduced by commit 143070e
> (mtd: physmap_of: Add multiple regions and concatenation support).
>
> info is needed (via drvdata) and freed in of_flash_remove(), therefore
> drvdata should be set right after allocation.
>
> Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
> ---
>  drivers/mtd/maps/physmap_of.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
> index 39d357b..32b4a5a 100644
> --- a/drivers/mtd/maps/physmap_of.c
> +++ b/drivers/mtd/maps/physmap_of.c
> @@ -214,12 +214,12 @@ static int __devinit of_flash_probe(struct of_device *dev,
>        if (!info)
>                goto err_out;
>
> +       dev_set_drvdata(&dev->dev, info);
> +
>        mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
> -       if (!info)
> +       if (!mtd_list)
>                goto err_out;
>
> -       dev_set_drvdata(&dev->dev, info);
> -
>        for (i = 0; i < count; i++) {
>                err = -ENXIO;
>                if (of_address_to_resource(dp, i, &res)) {
> --
> 1.6.3.3
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>

Patch

diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 39d357b..32b4a5a 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -214,12 +214,12 @@  static int __devinit of_flash_probe(struct of_device *dev,
 	if (!info)
 		goto err_out;
 
+	dev_set_drvdata(&dev->dev, info);
+
 	mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL);
-	if (!info)
+	if (!mtd_list)
 		goto err_out;
 
-	dev_set_drvdata(&dev->dev, info);
-
 	for (i = 0; i < count; i++) {
 		err = -ENXIO;
 		if (of_address_to_resource(dp, i, &res)) {