mtd: onenand: prevent memory leak in onenand_scan
diff mbox series

Message ID 20190925154302.17708-1-navid.emamdoost@gmail.com
State Changes Requested
Delegated to: Miquel Raynal
Headers show
Series
  • mtd: onenand: prevent memory leak in onenand_scan
Related show

Commit Message

Navid Emamdoost Sept. 25, 2019, 3:43 p.m. UTC
In onenand_scan if scan_bbt fails the allocated buffers should be
released.

Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 drivers/mtd/nand/onenand/onenand_base.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Markus Elfring Sept. 27, 2019, 3:24 p.m. UTC | #1
> In onenand_scan if scan_bbt fails the allocated buffers should be released.

Will an other change description be more appropriate?


How do you think about to add the tag “Fixes” here?

Regards,
Markus
Navid Emamdoost Sept. 30, 2019, 9:37 p.m. UTC | #2
Would you please take a look at this patch?

On Wed, Sep 25, 2019 at 10:43 AM Navid Emamdoost
<navid.emamdoost@gmail.com> wrote:
>
> In onenand_scan if scan_bbt fails the allocated buffers should be
> released.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  drivers/mtd/nand/onenand/onenand_base.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
> index 77bd32a683e1..79c01f42925a 100644
> --- a/drivers/mtd/nand/onenand/onenand_base.c
> +++ b/drivers/mtd/nand/onenand/onenand_base.c
> @@ -3977,8 +3977,11 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
>         this->badblockpos = ONENAND_BADBLOCK_POS;
>
>         ret = this->scan_bbt(mtd);
> -       if ((!FLEXONENAND(this)) || ret)
> +       if ((!FLEXONENAND(this)) || ret) {
> +               kfree(this->page_buf);
> +               kfree(this->oob_buf);
>                 return ret;
> +       }
>
>         /* Change Flex-OneNAND boundaries if required */
>         for (i = 0; i < MAX_DIES; i++)
> --
> 2.17.1
>
Miquel Raynal Oct. 4, 2019, 3:57 p.m. UTC | #3
Hi Navid,

Navid Emamdoost <navid.emamdoost@gmail.com> wrote on Mon, 30 Sep 2019
16:37:17 -0500:

> Would you please take a look at this patch?
> 
> On Wed, Sep 25, 2019 at 10:43 AM Navid Emamdoost
> <navid.emamdoost@gmail.com> wrote:
> >
> > In onenand_scan if scan_bbt fails the allocated buffers should be
> > released.
> >
> > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> > ---
> >  drivers/mtd/nand/onenand/onenand_base.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
> > index 77bd32a683e1..79c01f42925a 100644
> > --- a/drivers/mtd/nand/onenand/onenand_base.c
> > +++ b/drivers/mtd/nand/onenand/onenand_base.c
> > @@ -3977,8 +3977,11 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
> >         this->badblockpos = ONENAND_BADBLOCK_POS;
> >
> >         ret = this->scan_bbt(mtd);
> > -       if ((!FLEXONENAND(this)) || ret)
> > +       if ((!FLEXONENAND(this)) || ret) {
> > +               kfree(this->page_buf);

Apparently you missed:

#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
        kfree(this->verify_buf);
#endif

> > +               kfree(this->oob_buf);
> >                 return ret;
> > +       }
> >
> >         /* Change Flex-OneNAND boundaries if required */
> >         for (i = 0; i < MAX_DIES; i++)
> > --
> > 2.17.1
> >  
> 
> 

Thanks,
Miquèl
Navid Emamdoost Oct. 4, 2019, 5:20 p.m. UTC | #4
Thanks Miquel for pointing that out. v2 was sent.

Thank you,
Navid.

On Fri, Oct 4, 2019 at 10:57 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Navid,
>
> Navid Emamdoost <navid.emamdoost@gmail.com> wrote on Mon, 30 Sep 2019
> 16:37:17 -0500:
>
> > Would you please take a look at this patch?
> >
> > On Wed, Sep 25, 2019 at 10:43 AM Navid Emamdoost
> > <navid.emamdoost@gmail.com> wrote:
> > >
> > > In onenand_scan if scan_bbt fails the allocated buffers should be
> > > released.
> > >
> > > Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> > > ---
> > >  drivers/mtd/nand/onenand/onenand_base.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
> > > index 77bd32a683e1..79c01f42925a 100644
> > > --- a/drivers/mtd/nand/onenand/onenand_base.c
> > > +++ b/drivers/mtd/nand/onenand/onenand_base.c
> > > @@ -3977,8 +3977,11 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
> > >         this->badblockpos = ONENAND_BADBLOCK_POS;
> > >
> > >         ret = this->scan_bbt(mtd);
> > > -       if ((!FLEXONENAND(this)) || ret)
> > > +       if ((!FLEXONENAND(this)) || ret) {
> > > +               kfree(this->page_buf);
>
> Apparently you missed:
>
> #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
>         kfree(this->verify_buf);
> #endif
>
> > > +               kfree(this->oob_buf);
> > >                 return ret;
> > > +       }
> > >
> > >         /* Change Flex-OneNAND boundaries if required */
> > >         for (i = 0; i < MAX_DIES; i++)
> > > --
> > > 2.17.1
> > >
> >
> >
>
> Thanks,
> Miquèl

Patch
diff mbox series

diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
index 77bd32a683e1..79c01f42925a 100644
--- a/drivers/mtd/nand/onenand/onenand_base.c
+++ b/drivers/mtd/nand/onenand/onenand_base.c
@@ -3977,8 +3977,11 @@  int onenand_scan(struct mtd_info *mtd, int maxchips)
 	this->badblockpos = ONENAND_BADBLOCK_POS;
 
 	ret = this->scan_bbt(mtd);
-	if ((!FLEXONENAND(this)) || ret)
+	if ((!FLEXONENAND(this)) || ret) {
+		kfree(this->page_buf);
+		kfree(this->oob_buf);
 		return ret;
+	}
 
 	/* Change Flex-OneNAND boundaries if required */
 	for (i = 0; i < MAX_DIES; i++)