[PATCH v3] clk: starfive: jh7110: fix memory leak in jh7110_reset_controller_register() error path

From: Guangshuo Li

Date: Mon Apr 13 2026 - 10:38:03 EST


jh7110_reset_controller_register() allocates a jh71x0_reset_adev with
kzalloc() and sets jh7110_reset_adev_release() as the release callback
for its embedded auxiliary_device before calling auxiliary_device_init().

If auxiliary_device_init() fails, the function returns immediately
without freeing the allocated rdev. The release callback is not
available for this path, because it is only reached after a successful
auxiliary_device_init(), for example when auxiliary_device_add() fails
and auxiliary_device_uninit() is called.

The issue was identified by a static analysis tool I developed and
confirmed by manual review. Free rdev explicitly when
auxiliary_device_init() returns an error.

Fixes: edab7204afe5 ("clk: starfive: Add StarFive JH7110 system clock driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <lgs201920130244@xxxxxxxxx>
---
v3:
- clarify the changelog to describe the exact failure path
- note that the issue was identified by a static analysis tool
developed by me and confirmed by manual review
- apologize for sending the initial public posting as v2 by mistake

v2:
- initial public posting; v1 was mistakenly skipped

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