[PATCH] clk: bm1880: Release clocks before unmapping their registers
Jerome Brunet
jbrunet at baylibre.com
Fri Dec 4 00:23:44 PST 2026
> BM1880 registers clocks against device-managed register mappings but
> never removes the clocks on unbind or provider registration failure. A
> remaining clock can then read the unmapped registers.
>
> Manage the registrations and composite clock parts with the device, and
> unwind the entire set if a registration fails. Keep the PLL and divider
> initialization data available for a subsequent bind.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 1ab4601da55b ("clk: Add common clock driver for BM1880 SoC")
> Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
> ---
> drivers/clk/clk-bm1880.c | 188 +++++++++++++++++----------------------
> 1 file changed, 83 insertions(+), 105 deletions(-)
>
> diff --git a/drivers/clk/clk-bm1880.c b/drivers/clk/clk-bm1880.c
> index 122e57176c1c..30e7c519b199 100644
> --- a/drivers/clk/clk-bm1880.c
> +++ b/drivers/clk/clk-bm1880.c
> @@ -59,6 +59,7 @@
> static DEFINE_SPINLOCK(bm1880_clk_lock);
>
> struct bm1880_clock_data {
> + struct device *dev;
It is not necessary to store that, just make it an argument to you register functions
> void __iomem *pll_base;
> void __iomem *sys_base;
> struct clk_hw_onecell_data hw_data;
> @@ -99,7 +100,7 @@ struct bm1880_div_hw_clock {
> void __iomem *base;
> spinlock_t *lock;
> struct clk_hw hw;
> - struct clk_init_data init;
> + const struct clk_init_data *init;
> };
>
> struct bm1880_composite_clock {
> @@ -133,7 +134,7 @@ struct bm1880_pll_hw_clock {
> struct bm1880_pll_clock pll;
> void __iomem *base;
> struct clk_hw hw;
> - struct clk_init_data init;
> + const struct clk_init_data *init;
If the problem fixed is re-registration, please follow the discussion here and adjust
https://lore.kernel.org/linux-clk/20261124231751.83938-1-joshuacov@gmail.com/
> };
>
> static const struct clk_ops bm1880_pll_ops;
> @@ -174,7 +175,7 @@ static const struct clk_ops bm1880_clk_div_ops;
> .pll.id = _id, \
> .pll.name = _name, \
> .pll.reg = _reg, \
> - .hw.init = CLK_HW_INIT_PARENTS_DATA(_name, _parent, \
> + .init = CLK_HW_INIT_PARENTS_DATA(_name, _parent, \
> &bm1880_pll_ops, \
> _flags), \
> }
> @@ -188,7 +189,7 @@ static const struct clk_ops bm1880_clk_div_ops;
> .div.width = _width, \
> .div.initval = _initval, \
> .div.table = _table, \
> - .hw.init = CLK_HW_INIT_HW(_name, _parent, \
> + .init = CLK_HW_INIT_HW(_name, _parent, \
> &bm1880_clk_div_ops, \
> _flags), \
> }
> @@ -506,15 +507,16 @@ static const struct clk_ops bm1880_pll_ops = {
> };
>
> static struct clk_hw *bm1880_clk_register_pll(struct bm1880_pll_hw_clock *pll_clk,
> - void __iomem *sys_base)
> + struct bm1880_clock_data *data)
> {
> struct clk_hw *hw;
> int err;
>
> - pll_clk->base = sys_base;
> + pll_clk->base = data->pll_base;
> hw = &pll_clk->hw;
>
> - err = clk_hw_register(NULL, hw);
> + hw->init = pll_clk->init;
> + err = devm_clk_hw_register(data->dev, hw);
> if (err)
> return ERR_PTR(err);
... passing the whole data was not really needed then
--
Jerome
More information about the linux-arm-kernel
mailing list