clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex
Subsystems (2)
PATCH 1/1 clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex
Simplifies allocation by using a flexible array member.
Also allows using __counted_by for extra runtime analysis.
Signed-off-by Rosen Penev <[email protected]>
--- drivers/clk/nxp/clk-lpc18xx-ccu.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/clk/nxp/clk-lpc18xx-ccu.c +5 -9
@@ -27,8 +27,8 @@#define CCU_BRANCH_HAVE_DIV2 BIT(1)struct lpc18xx_branch_clk_data { -const char **name;int num; + const char *name[] __counted_by(num); };struct lpc18xx_clk_branch {
@@ -266,6 +266,7 @@ static void __init lpc18xx_ccu_init(struct device_node *np) {struct lpc18xx_branch_clk_data *clk_data;void __iomem *reg_base; +size_t size;int i, ret; reg_base =of_iomap (np,0 );
@@ -274,19 +275,14 @@ static void __init lpc18xx_ccu_init(struct device_node *np)return ; } - clk_data =kzalloc_obj (*clk_data); + size =of_property_count_strings (np,"clock-names" ); + clk_data =kzalloc_flex (*clk_data, name, size);if (!clk_data) {iounmap (reg_base);return ; } - clk_data->num =of_property_count_strings (np,"clock-names" ); - clk_data->name =kcalloc (clk_data->num,sizeof (char *),GFP_KERNEL ); -if (!clk_data->name) { -iounmap (reg_base); -kfree (clk_data); -return ; - } + clk_data->num = size;for (i =0 ; i < clk_data->num; i++) { ret = of_property_read_string_index(np, "clock-names", i,
Signature · 1 line
2.53.0
Quoted 5 lines · Rosen Penev
Simplifies allocation by using a flexible array member.
Also allows using
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>
Reviewed-by Gustavo A. R. Silva <[email protected]>
Thanks
-Gustavo
Quoted 49 lines
--- drivers/clk/nxp/clk-lpc18xx-ccu.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)drivers/clk/nxp/clk-lpc18xx-ccu.c +5
-9@@ -27,8 +27,8 @@#define CCU_BRANCH_HAVE_DIV2 BIT(1)struct lpc18xx_branch_clk_data { -const char **name;int num; + const char *name[] __counted_by(num); };struct lpc18xx_clk_branch {@@ -266,6 +266,7 @@ static void __init lpc18xx_ccu_init(struct device_node *np) {struct lpc18xx_branch_clk_data *clk_data;void __iomem *reg_base; +size_t size;int i, ret; reg_base =of_iomap (np,0 );@@ -274,19 +275,14 @@ static void __init lpc18xx_ccu_init(struct device_node *np)return ; } - clk_data =kzalloc_obj (*clk_data); + size =of_property_count_strings (np,"clock-names" ); + clk_data =kzalloc_flex (*clk_data, name, size);if (!clk_data) {iounmap (reg_base);return ; } - clk_data->num =of_property_count_strings (np,"clock-names" ); - clk_data->name =kcalloc (clk_data->num,sizeof (char *),GFP_KERNEL ); -if (!clk_data->name) { -iounmap (reg_base); -kfree (clk_data); -return ; - } + clk_data->num = size;for (i =0 ; i < clk_data->num; i++) { ret = of_property_read_string_index(np, "clock-names", i,
Quoting Rosen Penev (2026-03-05 19:25:40)
Quoted 6 lines
Simplifies allocation by using a flexible array member.
Also allows using
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>---
Applied to clk-next