[PATCH v2] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path
From: Guangshuo Li
Date: Sun Apr 12 2026 - 08:55:45 EST
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@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
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