[PATCH 03/10] clk: starfive: jh7110-sys: Use devres for PLL0 clock and notifier

From: Lee Jones

Date: Fri Nov 27 2026 - 14:26:52 EST


jh7110_syscrg_probe() allocates priv with devm_kzalloc_flex() but
acquires pll0_out with clk_get() and registers &priv->pll_clk_nb with
unmanaged clk_notifier_register(). If any subsequent step in probe
fails, devres frees priv while the notifier stays registered on
pll0_out, resulting in a use-after-free on the next rate change and a
leaked clock reference.

Use devm_clk_get() and devm_clk_notifier_register() so both the notifier
and clock reference are released automatically in LIFO order before priv
is freed.

Fixes: 538d5477b252 ("clk: starfive: jh7110-sys: Add notifier for PLL0 clock")
Closes: https://sashiko.dev/#/bug/linux-43575972-eb4c-4bf9-8cfe-cef64199b7e2
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/clk/starfive/clk-starfive-jh7110-sys.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/starfive/clk-starfive-jh7110-sys.c b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
index 44766b094b60..02ecf32fffdc 100644
--- a/drivers/clk/starfive/clk-starfive-jh7110-sys.c
+++ b/drivers/clk/starfive/clk-starfive-jh7110-sys.c
@@ -422,7 +422,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
return PTR_ERR(priv->base);

/* Use fixed factor clocks if can not get the PLL clocks from DTS */
- pllclk = clk_get(priv->dev, "pll0_out");
+ pllclk = devm_clk_get(priv->dev, "pll0_out");
if (IS_ERR(pllclk)) {
/* 24MHz -> 1000.0MHz */
priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out",
@@ -431,7 +431,8 @@ 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.56.1.839.g22a8290db9-goog