Skip to content

Commit

Permalink
mtd: plat-ram: correctly free memory on error path in platram_probe()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Baskov Evgeiny authored and Miquel Raynal committed Dec 10, 2020
1 parent 875330f commit 8c293f5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/mtd/maps/plat-ram.c
Original file line number Diff line number Diff line change
@@ -177,19 +177,24 @@ 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. */
err = mtd_device_register(info->mtd, NULL, 0);
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);

0 comments on commit 8c293f5

Please sign in to comment.