[PATCH] mfd: syscon: Put the clock after regmap_exit()
From: Arun Iyengar via B4 Relay
Date: Thu Nov 19 2026 - 11:51:02 EST
From: Arun Iyengar <aiyengar1990@xxxxxxxxx>
On the error path, of_syscon_register() puts the clock before
regmap_exit(), which then unprepares the freed clock. This happens
when the reset lookup fails, e.g. with -EPROBE_DEFER.
Put the clock after regmap_exit().
Fixes: a00406b71c5f ("mfd: syscon: Add optional clock support")
Fixes: 7d1e3bd94828 ("mfd: syscon: Allow reset control for syscon devices")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Closes: https://lore.kernel.org/r/179493691305.3136.16311404541139130213@xxxxxxxxxx
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
A related regmap patch ("regmap: mmio: Don't attach the clock if
clk_prepare() fails") is sent separately; neither depends on the other.
Tested on an Orange Pi 5 (RK3588S), 7.3 with KASAN, together with the
regmap patch: with a forced reset lookup failure, a use-after-free in
clk_unprepare() is reported without the two patches and nothing with both.
Developed with Claude (Anthropic), which wrote the code and the commit
message. I reviewed every change.
---
drivers/mfd/syscon.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 21a7fcdd2737..3ff4e024542b 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -132,13 +132,13 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
} else {
ret = regmap_mmio_attach_clk(regmap, clk);
if (ret)
- goto err_attach_clk;
+ goto err_clk;
}
reset = of_reset_control_get_optional_exclusive(np, NULL);
if (IS_ERR(reset)) {
ret = PTR_ERR(reset);
- goto err_attach_clk;
+ goto err_clk;
}
ret = reset_control_deassert(reset);
@@ -155,11 +155,10 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
err_reset:
reset_control_put(reset);
-err_attach_clk:
- if (!IS_ERR(clk))
- clk_put(clk);
err_clk:
regmap_exit(regmap);
+ if (!IS_ERR(clk))
+ clk_put(clk);
err_regmap:
iounmap(base);
return ERR_PTR(ret);
---
base-commit: e5bcc8e02e570e3eee46d4cebefd552cc7c9e843
change-id: 20261119-syscon-clk-uaf-5ff259e0fa15
Best regards,
--
Arun Iyengar <aiyengar1990@xxxxxxxxx>