public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex
@ 2026-03-06  3:25 Rosen Penev
  2026-03-06  4:08 ` Gustavo A. R. Silva
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-06  3:25 UTC (permalink / raw)
  To: linux-clk
  Cc: Michael Turquette, Stephen Boyd, Vladimir Zapolskiy, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/LPC18XX ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Simplifies allocation by using a flexible array member.

Also allows using __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/clk/nxp/clk-lpc18xx-ccu.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/nxp/clk-lpc18xx-ccu.c b/drivers/clk/nxp/clk-lpc18xx-ccu.c
index dcb6d0c0b41a..3793e701835f 100644
--- a/drivers/clk/nxp/clk-lpc18xx-ccu.c
+++ b/drivers/clk/nxp/clk-lpc18xx-ccu.c
@@ -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,
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex
  2026-03-06  3:25 [PATCH] clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex Rosen Penev
@ 2026-03-06  4:08 ` Gustavo A. R. Silva
  0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2026-03-06  4:08 UTC (permalink / raw)
  To: Rosen Penev, linux-clk
  Cc: Michael Turquette, Stephen Boyd, Vladimir Zapolskiy, Kees Cook,
	Gustavo A. R. Silva, moderated list:ARM/LPC18XX ARCHITECTURE,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b



On 3/6/26 12:25, Rosen Penev wrote:
> Simplifies allocation by using a flexible array member.
> 
> Also allows using __counted_by for extra runtime analysis.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
-Gustavo

> ---
>   drivers/clk/nxp/clk-lpc18xx-ccu.c | 14 +++++---------
>   1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/clk/nxp/clk-lpc18xx-ccu.c b/drivers/clk/nxp/clk-lpc18xx-ccu.c
> index dcb6d0c0b41a..3793e701835f 100644
> --- a/drivers/clk/nxp/clk-lpc18xx-ccu.c
> +++ b/drivers/clk/nxp/clk-lpc18xx-ccu.c
> @@ -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,



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-06 19:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06  3:25 [PATCH] clk-lpc18xx-ccu: kzalloc + kcalloc to kzalloc_flex Rosen Penev
2026-03-06  4:08 ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox