[PATCH] clk: aspeed: Manage AST2700 gate and divider clocks
Guangshuo Li
liguangshuo at mail.sdu.edu.cn
Sun Nov 29 08:26:18 PST 2026
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 62f490d9e188..963cc271ebd8 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;
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))
+
void clk_unregister_divider(struct clk *clk);
void clk_hw_unregister_divider(struct clk_hw *hw);
base-commit: d8f05ec001e838cdb94fc14efa7c411e676f9ab9
--
2.43.0
More information about the linux-arm-kernel
mailing list