[PATCH v2] mtd: onenand: prevent memory leak in onenand_scan
From: Navid Emamdoost
Date: Fri Oct 04 2019 - 13:19:25 EST
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@xxxxxxxxx>
---
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(-)
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++)
--
2.17.1