[PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind

From: Lee Jones

Date: Mon Nov 23 2026 - 15:01:15 EST


nct3018y_clkout_register_clk() registers the CLKOUT clock via
devm_clk_register() but adds the OF clock provider with unmanaged
of_clk_add_provider() and never removes it. When the driver unbinds or
devm_rtc_register_device() fails, devres unregisters and frees struct
clk and nct3018y state while leaving a dangling pointer on the global
of_clk_providers list, leaking the provider entry and OF node reference
and causing a use-after-free on subsequent clock lookups.

Use devm_of_clk_add_hw_provider() so the OF clock provider is removed
automatically before the clock and driver state are released.

Fixes: 5adbaed16cc6 ("rtc: Add NCT3018Y real time clock driver")
Closes: https://sashiko.dev/#/bug/linux-9509654b-12c7-4bd1-b189-f52692af9457
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/rtc/rtc-nct3018y.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c
index c770450e48b4..8349ddd1a9d6 100644
--- a/drivers/rtc/rtc-nct3018y.c
+++ b/drivers/rtc/rtc-nct3018y.c
@@ -479,7 +479,8 @@ static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw);

if (!IS_ERR(clk))
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ devm_of_clk_add_hw_provider(&client->dev, of_clk_hw_simple_get,
+ &nct3018y->clkout_hw);

return clk;
}
--
2.56.1.750.gf70dc682cf-goog