diff mbox series

[v2] mtd: onenand: prevent memory leak in onenand_scan

Message ID 20191004171909.6378-1-navid.emamdoost@gmail.com
State Changes Requested
Delegated to: Miquel Raynal
Headers show
Series [v2] mtd: onenand: prevent memory leak in onenand_scan | expand

Commit Message

Navid Emamdoost Oct. 4, 2019, 5:19 p.m. UTC
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")
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).
---
 drivers/mtd/nand/onenand/onenand_base.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Markus Elfring Oct. 5, 2019, 2:04 p.m. UTC | #1
> In onenand_scan if scan_bbt fails the allocated buffers for oob_buf,
> verify_buf, and page_buf should be released.

Can a wording like the following be nicer for the change description?

  Release the memory for the buffers “oob_buf”, “verify_buf” and “page_buf”
  after a call of the function “scan_bbt” failed in the implementation
  of the function “onenand_scan”.


> Fixes: 5988af231978 ("mtd: Flex-OneNAND support")> ---
> Changes in v2:> for the hint).

Did you take another review comment into account for this patch change log?


> ---

Please replace the delimiter at this place by a blank line in subsequent messages.


>  drivers/mtd/nand/onenand/onenand_base.c | 8 +++++++-
…


Regards,
Markus
Miquel Raynal Oct. 7, 2019, 8:54 a.m. UTC | #2
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
diff mbox series

Patch

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