[PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
Michael Ellerman
mpe at ellerman.id.au
Mon Dec 13 13:07:18 AEDT 2021
xkernel <xkernel.wang at foxmail.com> 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);
>
> --
More information about the Linuxppc-dev
mailing list