All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: renesas: fix a double free on error
@ 2021-06-17 13:37 Dan Carpenter
  2021-06-17 13:45 ` Geert Uytterhoeven
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2021-06-17 13:37 UTC (permalink / raw)
  To: Geert Uytterhoeven, Lad Prabhakar
  Cc: Michael Turquette, Stephen Boyd, Biju Das, linux-renesas-soc,
	linux-clk, kernel-janitors

The "clock" pointer is allocated with devm_kzalloc() so freeing it
here will lead to a double free.

Fixes: ef3c613ccd68 ("clk: renesas: Add CPG core wrapper for RZ/G2L SoC")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/clk/renesas/renesas-rzg2l-cpg.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/clk/renesas/renesas-rzg2l-cpg.c b/drivers/clk/renesas/renesas-rzg2l-cpg.c
index 5009b9e48b13..9516fb4d93e2 100644
--- a/drivers/clk/renesas/renesas-rzg2l-cpg.c
+++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c
@@ -473,7 +473,6 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
 fail:
 	dev_err(dev, "Failed to register %s clock %s: %ld\n", "module",
 		mod->name, PTR_ERR(clk));
-	kfree(clock);
 }
 
 #define rcdev_to_priv(x)	container_of(x, struct rzg2l_cpg_priv, rcdev)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: renesas: fix a double free on error
  2021-06-17 13:37 [PATCH] clk: renesas: fix a double free on error Dan Carpenter
@ 2021-06-17 13:45 ` Geert Uytterhoeven
  2021-06-17 14:04   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2021-06-17 13:45 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Lad Prabhakar, Michael Turquette, Stephen Boyd, Biju Das,
	Linux-Renesas, linux-clk, kernel-janitors

Hi Dan,

On Thu, Jun 17, 2021 at 3:38 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> The "clock" pointer is allocated with devm_kzalloc() so freeing it
> here will lead to a double free.
>
> Fixes: ef3c613ccd68 ("clk: renesas: Add CPG core wrapper for RZ/G2L SoC")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks for your patch!

While the double free is unlikely to happen (the error is not
propagated upstream, and the driver cannot be unloaded), kernel
test robot reported two of these errors.  The other one is at line 202.
Care to fix that as well?

> --- a/drivers/clk/renesas/renesas-rzg2l-cpg.c
> +++ b/drivers/clk/renesas/renesas-rzg2l-cpg.c
> @@ -473,7 +473,6 @@ rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod,
>  fail:
>         dev_err(dev, "Failed to register %s clock %s: %ld\n", "module",
>                 mod->name, PTR_ERR(clk));
> -       kfree(clock);
>  }

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clk: renesas: fix a double free on error
  2021-06-17 13:45 ` Geert Uytterhoeven
@ 2021-06-17 14:04   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2021-06-17 14:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Lad Prabhakar, Michael Turquette, Stephen Boyd, Biju Das,
	Linux-Renesas, linux-clk, kernel-janitors

On Thu, Jun 17, 2021 at 03:45:50PM +0200, Geert Uytterhoeven wrote:
> Hi Dan,
> 
> On Thu, Jun 17, 2021 at 3:38 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > The "clock" pointer is allocated with devm_kzalloc() so freeing it
> > here will lead to a double free.
> >
> > Fixes: ef3c613ccd68 ("clk: renesas: Add CPG core wrapper for RZ/G2L SoC")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks for your patch!
> 
> While the double free is unlikely to happen (the error is not
> propagated upstream, and the driver cannot be unloaded), kernel
> test robot reported two of these errors.  The other one is at line 202.
> Care to fix that as well?

Yeah, sure.  I'll clean up the NULL vs error pointer mixing as well.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-17 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 13:37 [PATCH] clk: renesas: fix a double free on error Dan Carpenter
2021-06-17 13:45 ` Geert Uytterhoeven
2021-06-17 14:04   ` Dan Carpenter

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.