diff options
author | Baskov Evgeiny <baskov@ispras.ru> | 2020-11-13 19:05:37 +0300 |
---|---|---|
committer | Miquel Raynal <miquel.raynal@bootlin.com> | 2020-12-11 00:37:32 +0300 |
commit | 8c293f545419c0d3da9a2a70df0311aa4027a820 (patch) | |
tree | 686a6c8291e7112d359085608ba4aaedd7101961 | |
parent | 875330f87a057a7d9831cd6a9dabf39185d15a92 (diff) | |
download | linux-8c293f545419c0d3da9a2a70df0311aa4027a820.tar.xz |
mtd: plat-ram: correctly free memory on error path in platram_probe()
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>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20201113160537.899-1-baskov@ispras.ru
-rw-r--r-- | drivers/mtd/maps/plat-ram.c | 11 |
1 files 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); |