[PATCH] clk: starfive: jh7110-sys: Use devm_clk_notifier_register()

Haotian Zhang posted 1 patch 2 months, 1 week ago
drivers/clk/starfive/clk-starfive-jh7110-sys.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] clk: starfive: jh7110-sys: Use devm_clk_notifier_register()
Posted by Haotian Zhang 2 months, 1 week ago
The clk_notifier_register() in jh7110_syscrg_probe() is not unregistered
in the error path, leading to a resource leak and potential use-after-free
if probe fails after the notifier is registered.

Use devm_clk_notifier_register() instead to automatically unregister
the notifier.

Fixes: 538d5477b252 ("clk: starfive: jh7110-sys: Add notifier for PLL0 clock")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/clk/starfive/clk-starfive-jh7110-sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
index 52833d4241c5..4f915038bd4b 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
@@ -430,7 +430,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
 			return PTR_ERR(priv->pll[0]);
 	} else {
 		priv->pll_clk_nb.notifier_call = jh7110_pll0_clk_notifier_cb;
-		ret = clk_notifier_register(pllclk, &priv->pll_clk_nb);
+		ret = devm_clk_notifier_register(priv->dev, pllclk, &priv->pll_clk_nb);
 		if (ret)
 			return ret;
 		priv->pll[0] = NULL;
-- 
2.50.1.windows.1
Re: [PATCH] clk: starfive: jh7110-sys: Use devm_clk_notifier_register()
Posted by Emil Renner Berthing 2 months, 1 week ago
Quoting Haotian Zhang (2025-11-26 04:25:34)
> The clk_notifier_register() in jh7110_syscrg_probe() is not unregistered
> in the error path, leading to a resource leak and potential use-after-free
> if probe fails after the notifier is registered.
>
> Use devm_clk_notifier_register() instead to automatically unregister
> the notifier.
>
> Fixes: 538d5477b252 ("clk: starfive: jh7110-sys: Add notifier for PLL0 clock")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>

Thanks!

Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>