Skip to content

Commit

Permalink
ARM: mmp: Fix failure to remove sram device
Browse files Browse the repository at this point in the history
Make sure in .probe() to set driver data before the function is left to
make it possible in .remove() to undo the actions done.

This fixes a potential memory leak and stops returning an error code in
.remove() that is ignored by the driver core anyhow.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
  • Loading branch information
Uwe Kleine-König authored and Arnd Bergmann committed Feb 25, 2022
1 parent 022e522 commit 4036b29
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions arch/arm/mach-mmp/sram.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ static int sram_probe(struct platform_device *pdev)
if (!info)
return -ENOMEM;

platform_set_drvdata(pdev, info);

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "no memory resource defined\n");
Expand Down Expand Up @@ -107,8 +109,6 @@ static int sram_probe(struct platform_device *pdev)
list_add(&info->node, &sram_bank_list);
mutex_unlock(&sram_lock);

platform_set_drvdata(pdev, info);

dev_info(&pdev->dev, "initialized\n");
return 0;

Expand All @@ -127,17 +127,19 @@ static int sram_remove(struct platform_device *pdev)
struct sram_bank_info *info;

info = platform_get_drvdata(pdev);
if (info == NULL)
return -ENODEV;

mutex_lock(&sram_lock);
list_del(&info->node);
mutex_unlock(&sram_lock);
if (info->sram_size) {
mutex_lock(&sram_lock);
list_del(&info->node);
mutex_unlock(&sram_lock);

gen_pool_destroy(info->gpool);
iounmap(info->sram_virt);
kfree(info->pool_name);
}

gen_pool_destroy(info->gpool);
iounmap(info->sram_virt);
kfree(info->pool_name);
kfree(info);

return 0;
}

Expand Down

0 comments on commit 4036b29

Please sign in to comment.