public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path
@ 2026-04-12 12:54 Guangshuo Li
  2026-04-13 16:38 ` Brian Masney
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-04-12 12:54 UTC (permalink / raw)
  To: Emil Renner Berthing, Hal Feng, Michael Turquette, Stephen Boyd,
	Conor Dooley, linux-clk, linux-kernel
  Cc: Guangshuo Li, stable

jh7110_reset_controller_register() allocates a jh71x0_reset_adev with
kzalloc() before calling auxiliary_device_init().

When auxiliary_device_init() returns an error, the function exits
without freeing rdev. Since the release callback is only expected to
handle cleanup after successful initialization, rdev should be freed
explicitly in this path.

Add the missing kfree(rdev) before returning from the
auxiliary_device_init() error path.

Fixes: edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/clk/starfive/clk-starfive-jh7110-sys.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
index 52833d4241c5..55cd0ccbdb84 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
@@ -360,8 +360,10 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv,
 	adev->id = adev_id;
 
 	ret = auxiliary_device_init(adev);
-	if (ret)
+	if (ret) {
+		kfree(rdev);
 		return ret;
+	}
 
 	ret = auxiliary_device_add(adev);
 	if (ret) {
-- 
2.43.0


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

* Re: [PATCH v2] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path
  2026-04-12 12:54 [PATCH v2] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path Guangshuo Li
@ 2026-04-13 16:38 ` Brian Masney
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Masney @ 2026-04-13 16:38 UTC (permalink / raw)
  To: Guangshuo Li
  Cc: Emil Renner Berthing, Hal Feng, Michael Turquette, Stephen Boyd,
	Conor Dooley, linux-clk, linux-kernel, stable

Hi Guangshuo,

On Sun, Apr 12, 2026 at 08:54:50PM +0800, Guangshuo Li wrote:
> jh7110_reset_controller_register() allocates a jh71x0_reset_adev with
> kzalloc() before calling auxiliary_device_init().
> 
> When auxiliary_device_init() returns an error, the function exits
> without freeing rdev. Since the release callback is only expected to
> handle cleanup after successful initialization, rdev should be freed
> explicitly in this path.
> 
> Add the missing kfree(rdev) before returning from the
> auxiliary_device_init() error path.
> 
> Fixes: edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/clk/starfive/clk-starfive-jh7110-sys.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
> index 52833d4241c5..55cd0ccbdb84 100644
> --- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
> +++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
> @@ -360,8 +360,10 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv,
>  	adev->id = adev_id;
>  
>  	ret = auxiliary_device_init(adev);
> -	if (ret)
> +	if (ret) {
> +		kfree(rdev);
>  		return ret;
> +	}
>  
>  	ret = auxiliary_device_add(adev);
>  	if (ret) {

There's actually another leak in the error path for
auxiliary_device_add(). I think this code should be
converted to devm_kzalloc().

There is no devm_kzalloc_obj() yet, however according to [1] that should
be coming soon.

[1] https://lore.kernel.org/lkml/20260330154108.GA3389518@killaraus.ideasonboard.com/

Brian


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

end of thread, other threads:[~2026-04-13 16:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-12 12:54 [PATCH v2] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path Guangshuo Li
2026-04-13 16:38 ` Brian Masney

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