clk: kirkwood: use kzalloc_flex
Subsystems (2)
PATCH 1/1 clk: kirkwood: use kzalloc_flex
Simplify allocation by using a flexible array member and kzalloc_flex to combine allocations.
Add __counted_by for extra runtime analysis. Move counting variable assignment to right after allocation as required by __counted_by.
Signed-off-by Rosen Penev <[email protected]>
--- drivers/clk/mvebu/kirkwood.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/clk/mvebu/kirkwood.c +8 -11
@@ -253,8 +253,8 @@ struct clk_muxing_soc_desc {struct clk_muxing_ctrl {spinlock_t *lock; -struct clk **muxes;int num_muxes; + struct clk *muxes[] __counted_by(num_muxes); };static const char *powersave_parents[] = {
@@ -297,21 +297,18 @@ static void __init kirkwood_clk_muxing_setup(struct device_node *np,if (WARN_ON (!base))return ; - ctrl =kzalloc_obj (*ctrl); -if (WARN_ON (!ctrl)) - goto ctrl_out; - -/* lock must already be initialized */ - ctrl->lock = &ctrl_gating_lock; -/* Count, allocate, and register clock muxes */ for (n =0 ; desc[n].name;) n++; + ctrl =kzalloc_flex (*ctrl, muxes, n); +if (WARN_ON (!ctrl)) + goto ctrl_out; + ctrl->num_muxes = n; - ctrl->muxes = kzalloc_objs(struct clk *, ctrl->num_muxes); -if (WARN_ON (!ctrl->muxes)) - goto muxes_out; + +/* lock must already be initialized */ + ctrl->lock = &ctrl_gating_lock;for (n =0 ; n < ctrl->num_muxes; n++) { ctrl->muxes[n] = clk_register_mux(NULL, desc[n].name,
Signature · 1 line
2.53.0
Quoted 38 lines · Rosen Penev
Simplify allocation by using a flexible array member and
kzalloc_flexto combine allocations.Add
__counted_byfor extra runtime analysis. Move counting variable assignment to right after allocation as required by__counted_by.Signed-off-by Rosen Penev <[email protected]>--- drivers/clk/mvebu/kirkwood.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)drivers/clk/mvebu/kirkwood.c +1
-8@@ -253,8 +253,8 @@ struct clk_muxing_soc_desc {struct clk_muxing_ctrl {spinlock_t *lock; -struct clk **muxes;int num_muxes; + struct clk *muxes[] __counted_by(num_muxes); };static const char *powersave_parents[] = {@@ -297,21 +297,18 @@ static void __init kirkwood_clk_muxing_setup(struct device_node *np,if (WARN_ON (!base))return ; - ctrl =kzalloc_obj (*ctrl); -if (WARN_ON (!ctrl)) - goto ctrl_out; - -/* lock must already be initialized */ - ctrl->lock = &ctrl_gating_lock; -/* Count, allocate, and register clock muxes */ for (n =0 ; desc[n].name;)
drivers/clk/mvebu/kirkwood.c static void __init kirkwood_clk_muxing_setup(struct device_node *np, · line 314
Quoted 10 lines
drivers/clk/mvebu/kirkwood.c +4
-3n++; + ctrl =kzalloc_flex (*ctrl, muxes, n); +if (WARN_ON (!ctrl)) + goto ctrl_out; + ctrl->num_muxes = n; - ctrl->muxes = kzalloc_objs(struct clk *, ctrl->num_muxes); -if (WARN_ON (!ctrl->muxes)) - goto muxes_out;
Question from Sashiko:
https://sashiko.dev/#/patchset/20260326045555.240730-1-rosenp%40gmail.com
This isn't a bug, but since the goto muxes_out error path was removed here,
should the muxes_out label and its kfree(ctrl) be removed at the end of the
function?
They appear to be dead code now and might cause an unused label warning:
return;
muxes_out:
kfree(ctrl);
ctrl_out:
iounmap(base);
}Brian
Quoted 9 lines
drivers/clk/mvebu/kirkwood.c +3
-0+ +/* lock must already be initialized */ + ctrl->lock = &ctrl_gating_lock;for (n =0 ; n < ctrl->num_muxes; n++) { ctrl->muxes[n] = clk_register_mux(NULL, desc[n].name,Signature · 1 line
2.53.0