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

From: Brian Masney

Date: Thu Nov 19 2026 - 09:58:57 EST


Hi Wang,

> 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);

There is a struct dev here, so devm_regmap_init_mmio() should fix this
in a cleaner way.

Brian

--
Brian Masney <masneyb@xxxxxxxxxx>