* Re: [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
@ 2021-12-13 2:26 ` xkernel.wang
0 siblings, 0 replies; 6+ messages in thread
From: xkernel.wang @ 2021-12-13 2:26 UTC (permalink / raw)
To: mpe, agust; +Cc: benh, paulus, linuxppc-dev, linux-kernel
Michael Ellerman <mpe@ellerman.id.au> wrote:
> > 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?
Yes, maybe you are right. I did that as I mentioned when gpt-regs is NULL, it
will return -ENOMEM, which is the same when gpt is NULL. So I suppose to
free it in time is better:
> gpt = devm_kzalloc(&ofdev->dev, sizeof *gpt, GFP_KERNEL);
> if (!gpt)
> return -ENOMEM;
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
@ 2021-12-13 2:26 ` xkernel.wang
0 siblings, 0 replies; 6+ messages in thread
From: xkernel.wang @ 2021-12-13 2:26 UTC (permalink / raw)
To: mpe, agust; +Cc: paulus, linuxppc-dev, linux-kernel
Michael Ellerman <mpe@ellerman.id.au> wrote:
> > 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?
Yes, maybe you are right. I did that as I mentioned when gpt-regs is NULL, it
will return -ENOMEM, which is the same when gpt is NULL. So I suppose to
free it in time is better:
> gpt = devm_kzalloc(&ofdev->dev, sizeof *gpt, GFP_KERNEL);
> if (!gpt)
> return -ENOMEM;
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
2021-12-12 11:43 ` xkernel
@ 2021-12-13 2:07 ` Michael Ellerman
-1 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2021-12-13 2:07 UTC (permalink / raw)
To: xkernel, agust; +Cc: benh, paulus, linuxppc-dev, linux-kernel, xkernel
xkernel <xkernel.wang@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);
>
> --
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
@ 2021-12-13 2:07 ` Michael Ellerman
0 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2021-12-13 2:07 UTC (permalink / raw)
To: xkernel, agust; +Cc: xkernel, paulus, linuxppc-dev, linux-kernel
xkernel <xkernel.wang@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);
>
> --
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
@ 2021-12-12 11:43 ` xkernel
0 siblings, 0 replies; 6+ messages in thread
From: xkernel @ 2021-12-12 11:43 UTC (permalink / raw)
To: agust; +Cc: mpe, benh, paulus, linuxppc-dev, linux-kernel, xkernel
When some internal memory errors happend in of_iomap(), we should free
gpt to prevent memory leak.
Signed-off-by: xkernel <xkernel.wang@foxmail.com>
---
arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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);
--
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak
@ 2021-12-12 11:43 ` xkernel
0 siblings, 0 replies; 6+ messages in thread
From: xkernel @ 2021-12-12 11:43 UTC (permalink / raw)
To: agust; +Cc: xkernel, linux-kernel, paulus, linuxppc-dev
When some internal memory errors happend in of_iomap(), we should free
gpt to prevent memory leak.
Signed-off-by: xkernel <xkernel.wang@foxmail.com>
---
arch/powerpc/platforms/52xx/mpc52xx_gpt.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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);
--
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-13 2:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 2:26 [PATCH] powerpc: mpc52xx_gpt: fix a potential memory leak xkernel.wang
2021-12-13 2:26 ` xkernel.wang
2021-12-13 2:26 ` xkernel.wang
-- strict thread matches above, loose matches on Subject: below --
2021-12-12 11:43 xkernel
2021-12-12 11:43 ` xkernel
2021-12-13 2:07 ` Michael Ellerman
2021-12-13 2:07 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.