[PATCH] ARM: mmp: Fix failure to remove sram device
Uwe Kleine-König
u.kleine-koenig at pengutronix.de
Mon Feb 21 04:14:12 PST 2022
[adding soc at kernel.org to Cc]
On Mon, Jul 26, 2021 at 10:01:58PM +0200, Uwe Kleine-König wrote:
> 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 at pengutronix.de>
This problem is still real and the patch not applied. Who feels
responsible to pick this up?
> ---
> arch/arm/mach-mmp/sram.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm/mach-mmp/sram.c b/arch/arm/mach-mmp/sram.c
> index 6794e2db1ad5..ecc46c31004f 100644
> --- a/arch/arm/mach-mmp/sram.c
> +++ b/arch/arm/mach-mmp/sram.c
> @@ -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");
> @@ -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;
>
> @@ -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;
> }
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20220221/cf66399e/attachment.sig>
More information about the linux-arm-kernel
mailing list