Skip to contentSkip to conversation

clk: renesas: fix a double free on error

PATCH Superseded Dan Carpenter 2 participants 3 messages Jun 17, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: renesas: fix a double free on error

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")
---
 drivers/clk/renesas/renesas-rzg2l-cpg.c | 1 -
 1 file changed, 1 deletion(-)
drivers/clk/renesas/renesas-rzg2l-cpg.c +0 -1
index 5009b9e48b13..9516fb4d93e2 100644
@@ -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)
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Dan,

Quoted 5 lines · Dan Carpenter

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")

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?

drivers/clk/renesas/renesas-rzg2l-cpg.c rzg2l_cpg_register_mod_clk(const struct rzg2l_mod_clk *mod, · line 476

Quoted 8 lines
drivers/clk/renesas/renesas-rzg2l-cpg.c +0 -1
@@ -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);
 }

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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

#2 lore raw
Quoted 9 lines · Geert Uytterhoeven

Hi Dan,

Quoted 5 lines · Dan Carpenter

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")
Quoted 6 lines

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