linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: fix memory leak in pxa2xx_flash_probe()
@ 2022-11-19  7:33 Zheng Yongjun
  2022-11-24 11:36 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Zheng Yongjun @ 2022-11-19  7:33 UTC (permalink / raw)
  To: miquel.raynal, richard, vigneshr, linux-mtd, linux-kernel

If '!info->map.virt' or '!info->mtd' success, 'info' should be
freed before return. Otherwise there is a memory leak.

Fixes: e644f7d62894 ("[MTD] MAPS: Merge Lubbock and Mainstone drivers into common PXA2xx driver")
Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
---
 drivers/mtd/maps/pxa2xx-flash.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index 1749dbbacc13..62a5bf41a6d7 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -64,6 +64,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
 	if (!info->map.virt) {
 		printk(KERN_WARNING "Failed to ioremap %s\n",
 		       info->map.name);
+		kfree(info);
 		return -ENOMEM;
 	}
 	info->map.cached = ioremap_cache(info->map.phys, info->map.size);
@@ -85,6 +86,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
 		iounmap((void *)info->map.virt);
 		if (info->map.cached)
 			iounmap(info->map.cached);
+		kfree(info);
 		return -EIO;
 	}
 	info->mtd->dev.parent = &pdev->dev;
--
2.17.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH] mtd: fix memory leak in pxa2xx_flash_probe()
  2022-11-19  7:33 [PATCH] mtd: fix memory leak in pxa2xx_flash_probe() Zheng Yongjun
@ 2022-11-24 11:36 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2022-11-24 11:36 UTC (permalink / raw)
  To: Zheng Yongjun, miquel.raynal, richard, vigneshr, linux-mtd, linux-kernel

On Sat, 2022-11-19 at 07:33:07 UTC, Zheng Yongjun wrote:
> If '!info->map.virt' or '!info->mtd' success, 'info' should be
> freed before return. Otherwise there is a memory leak.
> 
> Fixes: e644f7d62894 ("[MTD] MAPS: Merge Lubbock and Mainstone drivers into common PXA2xx driver")
> Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2022-11-24 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19  7:33 [PATCH] mtd: fix memory leak in pxa2xx_flash_probe() Zheng Yongjun
2022-11-24 11:36 ` Miquel Raynal

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).