linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd-ram: correctly free memory on error path in platram_probe()
@ 2020-11-13 16:05 Baskov Evgeiny
  2020-11-19 21:05 ` Miquel Raynal
  0 siblings, 1 reply; 2+ messages in thread
From: Baskov Evgeiny @ 2020-11-13 16:05 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Baskov Evgeiny, Richard Weinberger, Vignesh Raghavendra,
	linux-mtd, linux-kernel, ldv-project

If an error happens in mtd_device_parse_register or mtd_device_register,
memory allocated for struct platram_info is leaked.

Make platram_probe() call platram_remove() on all error paths
after struct platram_info allocation to correctly free resources.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Baskov Evgeiny <baskov@ispras.ru>
---
 drivers/mtd/maps/plat-ram.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 311742c78155..0bec7c791d17 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -177,8 +177,12 @@ static int platram_probe(struct platform_device *pdev)
 	err = mtd_device_parse_register(info->mtd, pdata->probes, NULL,
 					pdata->partitions,
 					pdata->nr_partitions);
-	if (!err)
-		dev_info(&pdev->dev, "registered mtd device\n");
+	if (err) {
+		dev_err(&pdev->dev, "failed to register mtd device\n");
+		goto exit_free;
+	}
+
+	dev_info(&pdev->dev, "registered mtd device\n");
 
 	if (pdata->nr_partitions) {
 		/* add the whole device. */
@@ -186,10 +190,11 @@ static int platram_probe(struct platform_device *pdev)
 		if (err) {
 			dev_err(&pdev->dev,
 				"failed to register the entire device\n");
+			goto exit_free;
 		}
 	}
 
-	return err;
+	return 0;
 
  exit_free:
 	platram_remove(pdev);
-- 
2.29.2


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

* Re: [PATCH] mtd-ram: correctly free memory on error path in platram_probe()
  2020-11-13 16:05 [PATCH] mtd-ram: correctly free memory on error path in platram_probe() Baskov Evgeiny
@ 2020-11-19 21:05 ` Miquel Raynal
  0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2020-11-19 21:05 UTC (permalink / raw)
  To: Baskov Evgeiny, Miquel Raynal
  Cc: ldv-project, Richard Weinberger, linux-kernel, linux-mtd,
	Vignesh Raghavendra

On Fri, 2020-11-13 at 16:05:37 UTC, Baskov Evgeiny wrote:
> If an error happens in mtd_device_parse_register or mtd_device_register,
> memory allocated for struct platram_info is leaked.
> 
> Make platram_probe() call platram_remove() on all error paths
> after struct platram_info allocation to correctly free resources.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Baskov Evgeiny <baskov@ispras.ru>

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

Miquel

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

end of thread, other threads:[~2020-11-19 21:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 16:05 [PATCH] mtd-ram: correctly free memory on error path in platram_probe() Baskov Evgeiny
2020-11-19 21:05 ` 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).