Skip to contentSkip to conversation

clk/ingenic: fix clock leak on clk_register_clkdev failure

PATCH In review WenTao Liang 3 participants 3 messages Jun 28 – Jul 7

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 clk/ingenic: fix clock leak on clk_register_clkdev failure

clk_register() succeeds but clk_register_clkdev() fails, and the error path jumps to out without calling clk_unregister or clk_put to release the registered clock. This leaks the clock object within the common clock framework, contrasting with the CGU_CLK_EXT type path which correctly calls clk_put on error.

Fixes b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")

---
Changes in v2:
- Fix patch format based on reviewer feedback

---
 drivers/clk/ingenic/cgu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/ingenic/cgu.c +3 -1
index 41e4c69131bd..b59b24d0e3cf 100644
@@ -774,8 +774,10 @@ static int ingenic_register_clock(struct ingenic_cgu *cgu, unsigned idx)
 	}
 
 	err = clk_register_clkdev(clk, clk_info->name, NULL);
-	if (err)
+	if (err) {
+		clk_unregister(clk);
 		goto out;
+	}
 
 	cgu->clocks.clks[idx] = clk;
 out:
Signature · 1 line
2.39.5 (Apple Git-154)
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · WenTao Liang

clk_register() succeeds but clk_register_clkdev() fails, and the error path jumps to out without calling clk_unregister or clk_put to release the registered clock. This leaks the clock object within the common clock framework

, contrasting with the CGU_CLK_EXT type path which correctly calls clk_put on error.

I would drop this part. Just focus on what you are fixing.

Quoted 2 lines

I don't see where on the v1 Greg suggested this, unless I am missing something?

Quoted 6 lines
Fixes b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")

---
Changes in v2:
- Fix patch format based on reviewer feedback

Link to v1: https://lore.kernel.org/linux-clk/[email protected]/

With those fixes:

Quoted 23 lines
---
 drivers/clk/ingenic/cgu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clk/ingenic/cgu.c +3 -1
index 41e4c69131bd..b59b24d0e3cf 100644
@@ -774,8 +774,10 @@ static int ingenic_register_clock(struct ingenic_cgu *cgu, unsigned idx)
 	}
 
 	err = clk_register_clkdev(clk, clk_info->name, NULL);
-	if (err)
+	if (err) {
+		clk_unregister(clk);
 		goto out;
+	}
 
 	cgu->clocks.clks[idx] = clk;
 out:
Signature · 1 line
2.39.5 (Apple Git-154)
maintainer
#2 lore raw
Quoted 10 lines · Brian Masney
Quoted 8 lines · WenTao Liang

clk_register() succeeds but clk_register_clkdev() fails, and the error path jumps to out without calling clk_unregister or clk_put to release the registered clock. This leaks the clock object within the common clock framework

, contrasting with the CGU_CLK_EXT type path which correctly calls clk_put on error.

Quoted 7 lines

I would drop this part. Just focus on what you are fixing.

Quoted 2 lines

I don't see where on the v1 Greg suggested this, unless I am missing something?

I did not.

Quoted 7 lines
Quoted 6 lines
Fixes b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")

---
Changes in v2:
- Fix patch format based on reviewer feedback

Quoted 5 lines

Link to v1: https://lore.kernel.org/linux-clk/[email protected]/

With those fixes:

All of these need to be dropped until the submitter learns how to properly submit things.

greg k-h