lkml.org 
[lkml]   [2019]   [Oct]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] mtd: onenand: prevent memory leak in onenand_scan
Hi Navid,

Navid Emamdoost <navid.emamdoost@gmail.com> wrote on Fri, 4 Oct 2019
12:19:05 -0500:

> In onenand_scan if scan_bbt fails the allocated buffers for oob_buf,
> verify_buf, and page_buf should be released.
>
> Fixes: 5988af231978 ("mtd: Flex-OneNAND support")

Missing Cc: stable@vger.kernel.org

> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> Changes in v2:
> -- added release for this->verify_buf (thanks to Miquel Raynal
> for the hint).
> ---

These three dashes are not needed.

> drivers/mtd/nand/onenand/onenand_base.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/onenand/onenand_base.c b/drivers/mtd/nand/onenand/onenand_base.c
> index 77bd32a683e1..6329ada3f15c 100644
> --- a/drivers/mtd/nand/onenand/onenand_base.c
> +++ b/drivers/mtd/nand/onenand/onenand_base.c
> @@ -3977,8 +3977,14 @@ 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->oob_buf);
> +#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
> + kfree(this->verify_buf);
> +#endif

Sorry for the ping-pong but actually, only the oob_buf and page_buf
have been introduced by the commit 5988af you point in the Fixes tag.

To help stable kernels maintainers I suggest you free the verify_buf
in a second patch which fixes:

4a8ce0b03071 mtd: onenand: allocate verify buffer in the core

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

Thanks,
Miquèl

\
 
 \ /
  Last update: 2019-10-07 10:54    [W:0.105 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site