[PATCH] clk: versatile-icst: release regmap on registration failure

From: Wang Haoran

Date: Thu Nov 19 2026 - 03:15:27 EST


icst_clk_register() creates a non-devm regmap with regmap_init_mmio() and
hands it to icst_clk_setup(), which on clk_register() failure only frees
its own structs and drops the regmap pointer, so the regmap and its
debugfs entry leak permanently. A name clash is a natural trigger: a DT
with N same-named auxosc children registers "osc" once and then fails
-EEXIST on every subsequent registration, leaking N-1 regmaps per boot.

Release the regmap with regmap_exit() when icst_clk_setup() fails.

Signed-off-by: Wang Haoran <wanghr2026@xxxxxxxxxxxxxxxxxx>
Fixes: 179c8fb3c2a6 ("clk: versatile-icst: convert to use regmap")
---

diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index 37334afee040..e9c7353aa5d5 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -407,14 +407,18 @@ struct clk *icst_clk_register(struct device *dev,
.reg_stride = 4,
};
struct regmap *map;
+ struct clk *clk;

map = regmap_init_mmio(dev, base, &icst_regmap_conf);
if (IS_ERR(map)) {
pr_err("could not initialize ICST regmap\n");
return ERR_CAST(map);
}
- return icst_clk_setup(dev, desc, name, parent_name, map,
- ICST_VERSATILE);
+ clk = icst_clk_setup(dev, desc, name, parent_name, map, ICST_VERSATILE);
+ if (IS_ERR(clk))
+ regmap_exit(map);
+
+ return clk;
}
EXPORT_SYMBOL_GPL(icst_clk_register);


---

PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):

Device tree injection, spliced into the QEMU virt machine DT:

reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
icst-regs@7f200000 { no-map; reg = <0x0 0x7f200000 0x0 0x1000>; }; };

syscon@7f200000 { compatible = "syscon"; reg = <0x0 0x7f200000 0x0 0x1000>;
osc@0 { compatible = "arm,versatile-cm-auxosc"; #clock-cells = <0>; };
osc@1 { compatible = "arm,versatile-cm-auxosc"; #clock-cells = <0>; }; };

Two same-compatible auxosc children make cm_osc_setup() run twice at boot
via CLK_OF_DECLARE: the first clk_register("osc") succeeds, the second hits
-EEXIST and its regmap is leaked. No trigger action is needed.

Result:

(null): error -EEXIST: failed to register clk 'osc' (0xffff000003407600)
===== LIVE REGMAP INSTANCES =====
drwxr-xr-x dummy0
drwxr-xr-x dummy1

dummy1 is the regmap leaked on the failed registration (dummy0 belongs to
the successfully registered clock). N duplicate nodes leak N-1 regmaps.

Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.