[PATCH] clk: aspeed: Manage AST2700 gate and divider clocks

Brian Masney masneyb at kernel.org
Mon Nov 30 09:44:16 PST 2026


Hi Guangshuo,

> The AST2700 driver registers the custom gates and table dividers without
> arranging cleanup. They can outlive the register mapping and lock that
> they use on probe failure or unbind.
> 
> Use managed registration for both clock types and allocate the gate
> alongside its registration.
> 
> This issue was found by our static analysis tool under development.
> 
> Fixes: fdc1eb624ddc ("clk: aspeed: add AST2700 clock driver")
> Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
> ---
>  drivers/clk/aspeed/clk-ast2700.c | 30 +++++++++++++-----------------
>  include/linux/clk-provider.h     | 22 ++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/clk/aspeed/clk-ast2700.c b/drivers/clk/aspeed/clk-ast2700.c
> index 495b7fa3395b..6c67f89e9d20 100644
> --- a/drivers/clk/aspeed/clk-ast2700.c
> +++ b/drivers/clk/aspeed/clk-ast2700.c
> @@ -826,10 +826,9 @@ static struct clk_hw *ast2700_clk_hw_register_gate(struct device *dev, const cha
>  {
>  	struct clk_init_data init = {};
>  	struct clk_gate *gate;
> -	struct clk_hw *hw;
> -	int ret = -EINVAL;
> +	int ret;
>  
> -	gate = kzalloc_obj(*gate);
> +	gate = devm_kzalloc_obj(dev, *gate);
>  	if (!gate)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -847,14 +846,11 @@ static struct clk_hw *ast2700_clk_hw_register_gate(struct device *dev, const cha
>  	gate->lock = lock;
>  	gate->hw.init = &init;
>  
> -	hw = &gate->hw;
> -	ret = clk_hw_register(dev, hw);
> -	if (ret) {
> -		kfree(gate);
> -		hw = ERR_PTR(ret);
> -	}
> +	ret = devm_clk_hw_register(dev, &gate->hw);
> +	if (ret)
> +		return ERR_PTR(ret);
>  
> -	return hw;
> +	return &gate->hw;
>  }
>  
>  static void ast2700_soc1_configure_i3c_clk(struct ast2700_clk_ctrl *clk_ctrl)
> @@ -994,13 +990,13 @@ static int ast2700_soc_clk_probe(struct platform_device *pdev)
>  
>  			reg = clk_ctrl->base + divider->reg;
>  			phw = hws[divider->parent_id];
> -			hws[id] = clk_hw_register_divider_table_parent_hw(dev, clk->name,
> -									  phw,
> -									  0, reg,
> -									  divider->bit_shift,
> -									  divider->bit_width, 0,
> -									  divider->div_table,
> -									  &clk_ctrl->lock);
> +			hws[id] = devm_clk_hw_register_divider_table_parent_hw(dev, clk->name, phw,
> +									       0, reg,
> +									       divider->bit_shift,
> +									       divider->bit_width,
> +									       0,
> +									       divider->div_table,
> +									       &clk_ctrl->lock);
>  		} else if (clk->type == CLK_GATE_ASPEED) {
>  			const struct ast2700_clk_gate_data *gate = &clk->data.gate;

The changes to this file look correct and need to be one patch.

>  
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index a355d1ee5189..ff5425171101 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -1019,6 +1019,28 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name,
>  				       (width), (clk_divider_flags), (table), \
>  				       (lock))
>  
> +/**
> + * devm_clk_hw_register_divider_table_parent_hw - register a table based divider
> + * clock with the clock framework
> + * @dev: device registering this clock
> + * @name: name of this clock
> + * @parent_hw: pointer to parent clk
> + * @flags: framework-specific flags
> + * @reg: register address to adjust divider
> + * @shift: number of bits to shift the bitfield
> + * @width: width of the bitfield
> + * @clk_divider_flags: divider-specific flags for this clock
> + * @table: array of divider/value pairs ending with a div set to 0
> + * @lock: shared register lock for this clock
> + */
> +#define devm_clk_hw_register_divider_table_parent_hw(dev, name, parent_hw, flags,  \
> +						reg, shift, width,	      \
> +						clk_divider_flags, table,     \
> +						lock)			      \
> +	__devm_clk_hw_register_divider((dev), NULL, (name), NULL, (parent_hw),     \
> +				  NULL, (flags), (reg), (shift), (width),     \
> +				  (clk_divider_flags), (table), (lock))

This needs to be split out into a separate patch. Also the reg and other
line starts don't line up with the dev parameter. The \ line
continuations at the end don't line up with the first line.

Brian

-- 
Brian Masney <masneyb at kernel.org>



More information about the linux-arm-kernel mailing list