clk: bcm: iproc-asiu: simplify allocation
Subsystems (2)
PATCH 1/1 clk: bcm: iproc-asiu: simplify allocation
Use kzalloc_flex and a flexible array member to combine allocations
While at it, take clk_data out of the struct and move it into probe. It's not used anywhere else.
Signed-off-by Rosen Penev <[email protected]>
--- drivers/clk/bcm/clk-iproc-asiu.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-)
drivers/clk/bcm/clk-iproc-asiu.c +10 -17
@@ -27,8 +27,7 @@ struct iproc_asiu {void __iomem *div_base;void __iomem *gate_base; -struct clk_hw_onecell_data *clk_data; -struct iproc_asiu_clk *clks; +struct iproc_asiu_clk clks[]; };#define to_asiu_clk (hw) container_of(hw, struct iproc_asiu_clk, hw)
@@ -184,22 +183,19 @@ void __init iproc_asiu_setup(struct device_node *node, {int i, ret;struct iproc_asiu *asiu; +struct clk_hw_onecell_data *clk_data;if (WARN_ON (!gate || !div))return ; - asiu =kzalloc_obj (*asiu); + asiu =kzalloc_flex (*asiu, clks, num_clks);if (WARN_ON (!asiu))return ; - asiu->clk_data =kzalloc_flex (*asiu->clk_data, hws, num_clks); -if (WARN_ON (!asiu->clk_data)) + clk_data =kzalloc_flex (*clk_data, hws, num_clks); +if (WARN_ON (!clk_data)) goto err_clks; - asiu->clk_data->num = num_clks; - - asiu->clks =kzalloc_objs (*asiu->clks, num_clks); -if (WARN_ON (!asiu->clks)) - goto err_asiu_clks; + clk_data->num = num_clks; asiu->div_base =of_iomap (node,0 );if (WARN_ON (!asiu->div_base))
@@ -236,11 +232,11 @@ void __init iproc_asiu_setup(struct device_node *node, ret =clk_hw_register (NULL , &asiu_clk->hw);if (WARN_ON (ret)) goto err_clk_register; - asiu->clk_data->hws[i] = &asiu_clk->hw; + clk_data->hws[i] = &asiu_clk->hw; } ret =of_clk_add_hw_provider (node, of_clk_hw_onecell_get, - asiu->clk_data); + clk_data);if (WARN_ON (ret)) goto err_clk_register;
@@ -248,17 +244,14 @@ void __init iproc_asiu_setup(struct device_node *node, err_clk_register:while (--i >=0 ) -clk_hw_unregister (asiu->clk_data->hws[i]); +clk_hw_unregister (clk_data->hws[i]);iounmap (asiu->gate_base); err_iomap_gate:iounmap (asiu->div_base); err_iomap_div: -kfree (asiu->clks); - -err_asiu_clks: -kfree (asiu->clk_data); +kfree (clk_data); err_clks:kfree (asiu);
Signature · 1 line
2.53.0
Quoted 6 lines · Rosen Penev
Use
kzalloc_flexand a flexible array member to combine allocationsWhile at it, take
clk_dataout of the struct and move it into probe. It's not used anywhere else.Signed-off-by Rosen Penev <[email protected]>
Reviewed-by Brian Masney <[email protected]>
Quoting Rosen Penev (2026-03-25 21:53:24)
Quoted 7 lines
Use
kzalloc_flexand a flexible array member to combine allocationsWhile at it, take
clk_dataout of the struct and move it into probe. It's not used anywhere else.Signed-off-by Rosen Penev <[email protected]>---
Applied to clk-next