* [PATCH] regmap: mmio: Don't attach the clock if clk_prepare() fails
@ 2026-11-19 16:50 Arun Iyengar via B4 Relay
0 siblings, 0 replies; only message in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:50 UTC (permalink / raw)
To: Mark Brown
Cc: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Johan Hovold, Maxime Ripard, linux-kernel, driver-core, stable,
Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
regmap_mmio_attach_clk() stores the clock before preparing it. If
clk_prepare() fails, regmap_exit() later unprepares a clock that was
never prepared, and the caller may already have put it.
Only attach the clock once it is prepared.
Fixes: 31895662f9ba ("regmap: mmio: Add function to attach a clock")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/179493691305.3136.16311404541139130213@kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
Found while fixing the error path of of_syscon_register(); that mfd patch
is sent separately and neither depends on the other.
Tested on an Orange Pi 5 (RK3588S), 7.3 with KASAN, together with the mfd
patch: with a forced clk_prepare() failure in of_syscon_register(), a
use-after-free in clk_unprepare() is reported without the two patches and
nothing with both. This patch was not run on its own.
Developed with Claude (Anthropic), which wrote the code and the commit
message. I reviewed every change.
---
drivers/base/regmap/regmap-mmio.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 1de2278fa572..6adbc950877c 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -590,11 +590,16 @@ EXPORT_SYMBOL_GPL(__devm_regmap_init_mmio_clk);
int regmap_mmio_attach_clk(struct regmap *map, struct clk *clk)
{
struct regmap_mmio_context *ctx = map->bus_context;
+ int ret;
+
+ ret = clk_prepare(clk);
+ if (ret)
+ return ret;
ctx->clk = clk;
ctx->attached_clk = true;
- return clk_prepare(ctx->clk);
+ return 0;
}
EXPORT_SYMBOL_GPL(regmap_mmio_attach_clk);
---
base-commit: 50b3d8bb527b11384153c4ca854c8610f4a55649
change-id: 20261119-regmap-mmio-attach-clk-f95ad7fd33a3
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 16:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 16:50 [PATCH] regmap: mmio: Don't attach the clock if clk_prepare() fails Arun Iyengar via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®