The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2] clk/ingenic: fix clock leak on clk_register_clkdev failure
@ 2026-06-28 12:28 WenTao Liang
  2026-07-06 19:59 ` Brian Masney
  0 siblings, 1 reply; 3+ messages in thread
From: WenTao Liang @ 2026-06-28 12:28 UTC (permalink / raw)
  To: paul, mturquette, sboyd
  Cc: bmasney, linux-mips, linux-clk, linux-kernel, WenTao Liang,
	Greg KH, stable

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.

Suggested-by: Greg KH <gregkh@linuxfoundation.org>
Fixes: b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")
Cc: stable@vger.kernel.org
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Fix patch format based on reviewer feedback
---
 drivers/clk/ingenic/cgu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ingenic/cgu.c b/drivers/clk/ingenic/cgu.c
index 41e4c69131bd..b59b24d0e3cf 100644
--- a/drivers/clk/ingenic/cgu.c
+++ b/drivers/clk/ingenic/cgu.c
@@ -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:
-- 
2.39.5 (Apple Git-154)


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

* Re: [PATCH v2] clk/ingenic: fix clock leak on clk_register_clkdev failure
  2026-06-28 12:28 [PATCH v2] clk/ingenic: fix clock leak on clk_register_clkdev failure WenTao Liang
@ 2026-07-06 19:59 ` Brian Masney
  2026-07-07  4:25   ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Masney @ 2026-07-06 19:59 UTC (permalink / raw)
  To: WenTao Liang
  Cc: paul, mturquette, sboyd, linux-mips, linux-clk, linux-kernel,
	Greg KH, stable

On Sun, Jun 28, 2026 at 08:28:11PM +0800, WenTao Liang wrote:
> 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.

> 
> Suggested-by: Greg KH <gregkh@linuxfoundation.org>

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

> Fixes: b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")
> Cc: stable@vger.kernel.org
> Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
> ---
> Changes in v2:
> - Fix patch format based on reviewer feedback

Link to v1: https://lore.kernel.org/linux-clk/20260626115644.33779-1-vulab@iscas.ac.cn/

With those fixes:

Reviewed-by: Brian Masney <bmasney@redhat.com>


> ---
>  drivers/clk/ingenic/cgu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/ingenic/cgu.c b/drivers/clk/ingenic/cgu.c
> index 41e4c69131bd..b59b24d0e3cf 100644
> --- a/drivers/clk/ingenic/cgu.c
> +++ b/drivers/clk/ingenic/cgu.c
> @@ -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:
> -- 
> 2.39.5 (Apple Git-154)
> 


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

* Re: [PATCH v2] clk/ingenic: fix clock leak on clk_register_clkdev failure
  2026-07-06 19:59 ` Brian Masney
@ 2026-07-07  4:25   ` Greg KH
  0 siblings, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-07-07  4:25 UTC (permalink / raw)
  To: Brian Masney
  Cc: WenTao Liang, paul, mturquette, sboyd, linux-mips, linux-clk,
	linux-kernel, stable

On Mon, Jul 06, 2026 at 03:59:06PM -0400, Brian Masney wrote:
> On Sun, Jun 28, 2026 at 08:28:11PM +0800, WenTao Liang wrote:
> > 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.
> 
> > 
> > Suggested-by: Greg KH <gregkh@linuxfoundation.org>
> 
> I don't see where on the v1 Greg suggested this, unless I am missing
> something?

I did not.

> > Fixes: b066303fb3e7 ("clk: ingenic: add driver for Ingenic SoC CGU clocks")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
> > ---
> > Changes in v2:
> > - Fix patch format based on reviewer feedback
> 
> Link to v1: https://lore.kernel.org/linux-clk/20260626115644.33779-1-vulab@iscas.ac.cn/
> 
> With those fixes:
> 
> Reviewed-by: Brian Masney <bmasney@redhat.com>

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

greg k-h

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

end of thread, other threads:[~2026-07-07  4:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-28 12:28 [PATCH v2] clk/ingenic: fix clock leak on clk_register_clkdev failure WenTao Liang
2026-07-06 19:59 ` Brian Masney
2026-07-07  4:25   ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox