Subject: Re: [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak

From: Michael Ellerman <[email-masked]>
Date: Mon, 13 Dec 2021 13:07:18 +1100

xkernel <[email-masked]> writes:
> When some internal memory errors happend in of_iomap(), we should free
> gpt to prevent memory leak.

But it's allocated with devm_kzalloc(), so the devres core is meant to
free it for us isn't it?

cheers

> diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
> index f862b48..c506cfd 100644
> --- a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
> +++ b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
> @@ -722,8 +722,10 @@ static int mpc52xx_gpt_probe(struct platform_device *ofdev)
>  	gpt->dev = &ofdev->dev;
>  	gpt->ipb_freq = mpc5xxx_get_bus_frequency(ofdev->dev.of_node);
>  	gpt->regs = of_iomap(ofdev->dev.of_node, 0);
> -	if (!gpt->regs)
> +	if (!gpt->regs) {
> +		devm_kfree(&ofdev->dev, gpt);
>  		return -ENOMEM;
> +	}
>  
>  	dev_set_drvdata(&ofdev->dev, gpt);
>  
> --