linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: fix memory leak in ONFI extended parameter page
@ 2013-09-17  1:31 Brian Norris
  2013-09-17  2:12 ` Huang Shijie
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Norris @ 2013-09-17  1:31 UTC (permalink / raw)
  To: David Woodhouse
  Cc: Artem Bityutskiy, Brian Norris, linux-mtd, Linux Kernel, Huang Shijie

This fixes a memory leak in the ONFI support code for detecting the
required ECC levels from this commit:

  commit 6dcbe0cdd83fb5f77be4f44c9e06c535281c375a
  Author: Huang Shijie <b32955@freescale.com>
  Date:   Wed May 22 10:28:27 2013 +0800

      mtd: get the ECC info from the Extended Parameter Page

In the success case, we never freed the 'ep' buffer.

Also, this fixes an oversight in the same commit where we (harmlessly)
freed the NULL pointer.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Cc: Huang Shijie <b32955@freescale.com>
---
David, if there are no objections, can you send this to Linus for 3.12?

If this doesn't make it into 3.12, then it will be -stable material.

 drivers/mtd/nand/nand_base.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index d4578a1..00022b4 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2869,10 +2869,8 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
 
 	len = le16_to_cpu(p->ext_param_page_length) * 16;
 	ep = kmalloc(len, GFP_KERNEL);
-	if (!ep) {
-		ret = -ENOMEM;
-		goto ext_out;
-	}
+	if (!ep)
+		return -ENOMEM;
 
 	/* Send our own NAND_CMD_PARAM. */
 	chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
@@ -2920,7 +2918,7 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
 	}
 
 	pr_info("ONFI extended param page detected.\n");
-	return 0;
+	ret = 0;
 
 ext_out:
 	kfree(ep);
-- 
1.8.4


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

* Re: [PATCH] mtd: nand: fix memory leak in ONFI extended parameter page
  2013-09-17  1:31 [PATCH] mtd: nand: fix memory leak in ONFI extended parameter page Brian Norris
@ 2013-09-17  2:12 ` Huang Shijie
  2013-09-19  4:15   ` Brian Norris
  0 siblings, 1 reply; 3+ messages in thread
From: Huang Shijie @ 2013-09-17  2:12 UTC (permalink / raw)
  To: Brian Norris; +Cc: David Woodhouse, Artem Bityutskiy, linux-mtd, Linux Kernel

于 2013年09月17日 09:31, Brian Norris 写道:
> This fixes a memory leak in the ONFI support code for detecting the
> required ECC levels from this commit:
>
>   commit 6dcbe0cdd83fb5f77be4f44c9e06c535281c375a
>   Author: Huang Shijie <b32955@freescale.com>
>   Date:   Wed May 22 10:28:27 2013 +0800
>
>       mtd: get the ECC info from the Extended Parameter Page
>
> In the success case, we never freed the 'ep' buffer.
>
> Also, this fixes an oversight in the same commit where we (harmlessly)
> freed the NULL pointer.
>
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> Cc: Huang Shijie <b32955@freescale.com>
> ---
> David, if there are no objections, can you send this to Linus for 3.12?
>
> If this doesn't make it into 3.12, then it will be -stable material.
>
>  drivers/mtd/nand/nand_base.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index d4578a1..00022b4 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -2869,10 +2869,8 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
>  
>  	len = le16_to_cpu(p->ext_param_page_length) * 16;
>  	ep = kmalloc(len, GFP_KERNEL);
> -	if (!ep) {
> -		ret = -ENOMEM;
> -		goto ext_out;
> -	}
> +	if (!ep)
> +		return -ENOMEM;
>  
>  	/* Send our own NAND_CMD_PARAM. */
>  	chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
> @@ -2920,7 +2918,7 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
>  	}
>  
>  	pr_info("ONFI extended param page detected.\n");
> -	return 0;
> +	ret = 0;
>  
>  ext_out:
>  	kfree(ep);
good catch!

Acked-by: Huang Shijie <b32955@freescale.com>


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

* Re: [PATCH] mtd: nand: fix memory leak in ONFI extended parameter page
  2013-09-17  2:12 ` Huang Shijie
@ 2013-09-19  4:15   ` Brian Norris
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Norris @ 2013-09-19  4:15 UTC (permalink / raw)
  To: Huang Shijie; +Cc: David Woodhouse, Artem Bityutskiy, linux-mtd, Linux Kernel

On Tue, Sep 17, 2013 at 10:12:57AM +0800, Huang Shijie wrote:
> 于 2013年09月17日 09:31, Brian Norris 写道:
> > This fixes a memory leak in the ONFI support code for detecting the
> > required ECC levels from this commit:
> >
> >   commit 6dcbe0cdd83fb5f77be4f44c9e06c535281c375a
> >   Author: Huang Shijie <b32955@freescale.com>
> >   Date:   Wed May 22 10:28:27 2013 +0800
> >
> >       mtd: get the ECC info from the Extended Parameter Page
> >
> > In the success case, we never freed the 'ep' buffer.
> >
> > Also, this fixes an oversight in the same commit where we (harmlessly)
> > freed the NULL pointer.
> >
> > Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> > Cc: Huang Shijie <b32955@freescale.com>
> > ---
> > David, if there are no objections, can you send this to Linus for 3.12?
> >
> > If this doesn't make it into 3.12, then it will be -stable material.
> >
> >  drivers/mtd/nand/nand_base.c | 8 +++-----
> >  1 file changed, 3 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> > index d4578a1..00022b4 100644
> > --- a/drivers/mtd/nand/nand_base.c
> > +++ b/drivers/mtd/nand/nand_base.c
> > @@ -2869,10 +2869,8 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
> >  
> >  	len = le16_to_cpu(p->ext_param_page_length) * 16;
> >  	ep = kmalloc(len, GFP_KERNEL);
> > -	if (!ep) {
> > -		ret = -ENOMEM;
> > -		goto ext_out;
> > -	}
> > +	if (!ep)
> > +		return -ENOMEM;
> >  
> >  	/* Send our own NAND_CMD_PARAM. */
> >  	chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1);
> > @@ -2920,7 +2918,7 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,
> >  	}
> >  
> >  	pr_info("ONFI extended param page detected.\n");
> > -	return 0;
> > +	ret = 0;
> >  
> >  ext_out:
> >  	kfree(ep);
> good catch!
> 
> Acked-by: Huang Shijie <b32955@freescale.com>

OK, pushed to l2-mtd.git. If I don't hear anything from David in a few
days, then I'll see about sending it upstream myself. He had time to
respond to your quad-SPI series but not to the pxa3xx compile failures
in his -rc1 pull request.

Brian

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

end of thread, other threads:[~2013-09-19  4:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-17  1:31 [PATCH] mtd: nand: fix memory leak in ONFI extended parameter page Brian Norris
2013-09-17  2:12 ` Huang Shijie
2013-09-19  4:15   ` Brian Norris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).