public inbox for linux-clk@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clk: mvebu: use kzalloc_flex
@ 2026-04-02  0:20 Rosen Penev
  2026-04-03 13:29 ` Brian Masney
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-04-02  0:20 UTC (permalink / raw)
  To: linux-clk
  Cc: Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Michael Turquette, Stephen Boyd, Kees Cook, Gustavo A. R. Silva,
	moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Use a flexible array member to combine kzalloc and kcalloc in one
allocation so they can be freed together.

Add __counted_by for extra runtime analysis. Move counting variable
assignment right after allocation as done by kzalloc_flex with GCC >=
15.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/clk/mvebu/common.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/mvebu/common.c b/drivers/clk/mvebu/common.c
index 28f2e1b2a932..4129690fcae0 100644
--- a/drivers/clk/mvebu/common.c
+++ b/drivers/clk/mvebu/common.c
@@ -189,10 +189,10 @@ DEFINE_SPINLOCK(ctrl_gating_lock);
 
 struct clk_gating_ctrl {
 	spinlock_t *lock;
-	struct clk **gates;
 	int num_gates;
 	void __iomem *base;
 	u32 saved_reg;
+	struct clk *gates[] __counted_by(num_gates);
 };
 
 static struct clk_gating_ctrl *ctrl;
@@ -257,24 +257,21 @@ void __init mvebu_clk_gating_setup(struct device_node *np,
 		clk_put(clk);
 	}
 
-	ctrl = kzalloc_obj(*ctrl);
+	/* Count, allocate, and register clock gates */
+	for (n = 0; desc[n].name;)
+		n++;
+
+	ctrl = kzalloc_flex(*ctrl, gates, n);
 	if (WARN_ON(!ctrl))
 		goto ctrl_out;
 
+	ctrl->num_gates = n;
+
 	/* lock must already be initialized */
 	ctrl->lock = &ctrl_gating_lock;
 
 	ctrl->base = base;
 
-	/* Count, allocate, and register clock gates */
-	for (n = 0; desc[n].name;)
-		n++;
-
-	ctrl->num_gates = n;
-	ctrl->gates = kzalloc_objs(*ctrl->gates, ctrl->num_gates);
-	if (WARN_ON(!ctrl->gates))
-		goto gates_out;
-
 	for (n = 0; n < ctrl->num_gates; n++) {
 		const char *parent =
 			(desc[n].parent) ? desc[n].parent : default_parent;
-- 
2.53.0


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

* Re: [PATCH] clk: mvebu: use kzalloc_flex
  2026-04-02  0:20 [PATCH] clk: mvebu: use kzalloc_flex Rosen Penev
@ 2026-04-03 13:29 ` Brian Masney
  2026-04-07  3:59 ` kernel test robot
  2026-04-07  3:59 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: Brian Masney @ 2026-04-03 13:29 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-clk, Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Michael Turquette, Stephen Boyd, Kees Cook, Gustavo A. R. Silva,
	moderated list:ARM/Marvell Kirkwood and Armada 370, 375, 38x,...,
	open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Hi Rosen,

On Wed, Apr 01, 2026 at 05:20:11PM -0700, Rosen Penev wrote:
> Use a flexible array member to combine kzalloc and kcalloc in one
> allocation so they can be freed together.
> 
> Add __counted_by for extra runtime analysis. Move counting variable
> assignment right after allocation as done by kzalloc_flex with GCC >=
> 15.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/clk/mvebu/common.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/clk/mvebu/common.c b/drivers/clk/mvebu/common.c
> index 28f2e1b2a932..4129690fcae0 100644
> --- a/drivers/clk/mvebu/common.c
> +++ b/drivers/clk/mvebu/common.c
> @@ -189,10 +189,10 @@ DEFINE_SPINLOCK(ctrl_gating_lock);
>  
>  struct clk_gating_ctrl {
>  	spinlock_t *lock;
> -	struct clk **gates;
>  	int num_gates;
>  	void __iomem *base;
>  	u32 saved_reg;
> +	struct clk *gates[] __counted_by(num_gates);
>  };
>  
>  static struct clk_gating_ctrl *ctrl;
> @@ -257,24 +257,21 @@ void __init mvebu_clk_gating_setup(struct device_node *np,
>  		clk_put(clk);
>  	}
>  
> -	ctrl = kzalloc_obj(*ctrl);
> +	/* Count, allocate, and register clock gates */
> +	for (n = 0; desc[n].name;)
> +		n++;
> +
> +	ctrl = kzalloc_flex(*ctrl, gates, n);
>  	if (WARN_ON(!ctrl))
>  		goto ctrl_out;
>  
> +	ctrl->num_gates = n;
> +
>  	/* lock must already be initialized */
>  	ctrl->lock = &ctrl_gating_lock;
>  
>  	ctrl->base = base;
>  
> -	/* Count, allocate, and register clock gates */
> -	for (n = 0; desc[n].name;)
> -		n++;
> -
> -	ctrl->num_gates = n;
> -	ctrl->gates = kzalloc_objs(*ctrl->gates, ctrl->num_gates);
> -	if (WARN_ON(!ctrl->gates))
> -		goto gates_out;

The gates_out label and kfree() needs to be removed.

Brian

> -
>  	for (n = 0; n < ctrl->num_gates; n++) {
>  		const char *parent =
>  			(desc[n].parent) ? desc[n].parent : default_parent;
> -- 
> 2.53.0
> 


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

* Re: [PATCH] clk: mvebu: use kzalloc_flex
  2026-04-02  0:20 [PATCH] clk: mvebu: use kzalloc_flex Rosen Penev
  2026-04-03 13:29 ` Brian Masney
@ 2026-04-07  3:59 ` kernel test robot
  2026-04-07  3:59 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-07  3:59 UTC (permalink / raw)
  To: Rosen Penev, linux-clk

Hi Rosen,

kernel test robot noticed the following build warnings:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v7.0-rc6 next-20260403]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/clk-mvebu-use-kzalloc_flex/20260405-093941
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20260402002011.89926-1-rosenp%40gmail.com
patch subject: [PATCH] clk: mvebu: use kzalloc_flex
config: arm-randconfig-001-20260405 (https://download.01.org/0day-ci/archive/20260405/202604051547.i2Xz9mGD-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260405/202604051547.i2Xz9mGD-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604051547.i2Xz9mGD-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/clk/mvebu/common.c: In function 'mvebu_clk_gating_setup':
>> drivers/clk/mvebu/common.c:289:1: warning: label 'gates_out' defined but not used [-Wunused-label]
     289 | gates_out:
         | ^~~~~~~~~


vim +/gates_out +289 drivers/clk/mvebu/common.c

a97fbc3ee3e2a5 Thierry Reding        2025-10-29  236  
a45184099affdd Sebastian Hesselbarth 2013-05-11  237  void __init mvebu_clk_gating_setup(struct device_node *np,
a45184099affdd Sebastian Hesselbarth 2013-05-11  238  				   const struct clk_gating_soc_desc *desc)
a45184099affdd Sebastian Hesselbarth 2013-05-11  239  {
a45184099affdd Sebastian Hesselbarth 2013-05-11  240  	struct clk *clk;
a45184099affdd Sebastian Hesselbarth 2013-05-11  241  	void __iomem *base;
a45184099affdd Sebastian Hesselbarth 2013-05-11  242  	const char *default_parent = NULL;
a45184099affdd Sebastian Hesselbarth 2013-05-11  243  	int n;
a45184099affdd Sebastian Hesselbarth 2013-05-11  244  
f571053152f660 Thomas Petazzoni      2014-11-21  245  	if (ctrl) {
7fbb639aea3538 Colin Ian King        2019-04-16  246  		pr_err("mvebu-clk-gating: cannot instantiate more than one gateable clock device\n");
f571053152f660 Thomas Petazzoni      2014-11-21  247  		return;
f571053152f660 Thomas Petazzoni      2014-11-21  248  	}
f571053152f660 Thomas Petazzoni      2014-11-21  249  
a45184099affdd Sebastian Hesselbarth 2013-05-11  250  	base = of_iomap(np, 0);
a45184099affdd Sebastian Hesselbarth 2013-05-11  251  	if (WARN_ON(!base))
a45184099affdd Sebastian Hesselbarth 2013-05-11  252  		return;
a45184099affdd Sebastian Hesselbarth 2013-05-11  253  
a45184099affdd Sebastian Hesselbarth 2013-05-11  254  	clk = of_clk_get(np, 0);
a45184099affdd Sebastian Hesselbarth 2013-05-11  255  	if (!IS_ERR(clk)) {
a45184099affdd Sebastian Hesselbarth 2013-05-11  256  		default_parent = __clk_get_name(clk);
a45184099affdd Sebastian Hesselbarth 2013-05-11  257  		clk_put(clk);
a45184099affdd Sebastian Hesselbarth 2013-05-11  258  	}
a45184099affdd Sebastian Hesselbarth 2013-05-11  259  
c3d0c641ee00fc Rosen Penev           2026-04-01  260  	/* Count, allocate, and register clock gates */
c3d0c641ee00fc Rosen Penev           2026-04-01  261  	for (n = 0; desc[n].name;)
c3d0c641ee00fc Rosen Penev           2026-04-01  262  		n++;
c3d0c641ee00fc Rosen Penev           2026-04-01  263  
c3d0c641ee00fc Rosen Penev           2026-04-01  264  	ctrl = kzalloc_flex(*ctrl, gates, n);
a45184099affdd Sebastian Hesselbarth 2013-05-11  265  	if (WARN_ON(!ctrl))
f98d007d332b81 Jisheng Zhang         2013-08-23  266  		goto ctrl_out;
a45184099affdd Sebastian Hesselbarth 2013-05-11  267  
c3d0c641ee00fc Rosen Penev           2026-04-01  268  	ctrl->num_gates = n;
c3d0c641ee00fc Rosen Penev           2026-04-01  269  
87e392164ab6c0 Mike Turquette        2014-08-27  270  	/* lock must already be initialized */
87e392164ab6c0 Mike Turquette        2014-08-27  271  	ctrl->lock = &ctrl_gating_lock;
a45184099affdd Sebastian Hesselbarth 2013-05-11  272  
f571053152f660 Thomas Petazzoni      2014-11-21  273  	ctrl->base = base;
f571053152f660 Thomas Petazzoni      2014-11-21  274  
a45184099affdd Sebastian Hesselbarth 2013-05-11  275  	for (n = 0; n < ctrl->num_gates; n++) {
a45184099affdd Sebastian Hesselbarth 2013-05-11  276  		const char *parent =
a45184099affdd Sebastian Hesselbarth 2013-05-11  277  			(desc[n].parent) ? desc[n].parent : default_parent;
a45184099affdd Sebastian Hesselbarth 2013-05-11  278  		ctrl->gates[n] = clk_register_gate(NULL, desc[n].name, parent,
a45184099affdd Sebastian Hesselbarth 2013-05-11  279  					desc[n].flags, base, desc[n].bit_idx,
87e392164ab6c0 Mike Turquette        2014-08-27  280  					0, ctrl->lock);
a45184099affdd Sebastian Hesselbarth 2013-05-11  281  		WARN_ON(IS_ERR(ctrl->gates[n]));
a45184099affdd Sebastian Hesselbarth 2013-05-11  282  	}
a45184099affdd Sebastian Hesselbarth 2013-05-11  283  
a45184099affdd Sebastian Hesselbarth 2013-05-11  284  	of_clk_add_provider(np, clk_gating_get_src, ctrl);
f98d007d332b81 Jisheng Zhang         2013-08-23  285  
a97fbc3ee3e2a5 Thierry Reding        2025-10-29  286  	register_syscore(&clk_gate_syscore);
f571053152f660 Thomas Petazzoni      2014-11-21  287  
f98d007d332b81 Jisheng Zhang         2013-08-23  288  	return;
f98d007d332b81 Jisheng Zhang         2013-08-23 @289  gates_out:

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

* Re: [PATCH] clk: mvebu: use kzalloc_flex
  2026-04-02  0:20 [PATCH] clk: mvebu: use kzalloc_flex Rosen Penev
  2026-04-03 13:29 ` Brian Masney
  2026-04-07  3:59 ` kernel test robot
@ 2026-04-07  3:59 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-07  3:59 UTC (permalink / raw)
  To: Rosen Penev, linux-clk

Hi Rosen,

kernel test robot noticed the following build warnings:

[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v7.0-rc6 next-20260403]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/clk-mvebu-use-kzalloc_flex/20260405-093941
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20260402002011.89926-1-rosenp%40gmail.com
patch subject: [PATCH] clk: mvebu: use kzalloc_flex
config: arm-defconfig (https://download.01.org/0day-ci/archive/20260405/202604051615.3w1LlikE-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project c80443cd37b2e2788cba67ffa180a6331e5f0791)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260405/202604051615.3w1LlikE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604051615.3w1LlikE-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/clk/mvebu/common.c:289:1: warning: unused label 'gates_out' [-Wunused-label]
     289 | gates_out:
         | ^~~~~~~~~~
   1 warning generated.


vim +/gates_out +289 drivers/clk/mvebu/common.c

a97fbc3ee3e2a53 Thierry Reding        2025-10-29  236  
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  237  void __init mvebu_clk_gating_setup(struct device_node *np,
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  238  				   const struct clk_gating_soc_desc *desc)
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  239  {
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  240  	struct clk *clk;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  241  	void __iomem *base;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  242  	const char *default_parent = NULL;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  243  	int n;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  244  
f571053152f6607 Thomas Petazzoni      2014-11-21  245  	if (ctrl) {
7fbb639aea35383 Colin Ian King        2019-04-16  246  		pr_err("mvebu-clk-gating: cannot instantiate more than one gateable clock device\n");
f571053152f6607 Thomas Petazzoni      2014-11-21  247  		return;
f571053152f6607 Thomas Petazzoni      2014-11-21  248  	}
f571053152f6607 Thomas Petazzoni      2014-11-21  249  
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  250  	base = of_iomap(np, 0);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  251  	if (WARN_ON(!base))
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  252  		return;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  253  
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  254  	clk = of_clk_get(np, 0);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  255  	if (!IS_ERR(clk)) {
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  256  		default_parent = __clk_get_name(clk);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  257  		clk_put(clk);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  258  	}
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  259  
c3d0c641ee00fc0 Rosen Penev           2026-04-01  260  	/* Count, allocate, and register clock gates */
c3d0c641ee00fc0 Rosen Penev           2026-04-01  261  	for (n = 0; desc[n].name;)
c3d0c641ee00fc0 Rosen Penev           2026-04-01  262  		n++;
c3d0c641ee00fc0 Rosen Penev           2026-04-01  263  
c3d0c641ee00fc0 Rosen Penev           2026-04-01  264  	ctrl = kzalloc_flex(*ctrl, gates, n);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  265  	if (WARN_ON(!ctrl))
f98d007d332b819 Jisheng Zhang         2013-08-23  266  		goto ctrl_out;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  267  
c3d0c641ee00fc0 Rosen Penev           2026-04-01  268  	ctrl->num_gates = n;
c3d0c641ee00fc0 Rosen Penev           2026-04-01  269  
87e392164ab6c0f Mike Turquette        2014-08-27  270  	/* lock must already be initialized */
87e392164ab6c0f Mike Turquette        2014-08-27  271  	ctrl->lock = &ctrl_gating_lock;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  272  
f571053152f6607 Thomas Petazzoni      2014-11-21  273  	ctrl->base = base;
f571053152f6607 Thomas Petazzoni      2014-11-21  274  
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  275  	for (n = 0; n < ctrl->num_gates; n++) {
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  276  		const char *parent =
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  277  			(desc[n].parent) ? desc[n].parent : default_parent;
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  278  		ctrl->gates[n] = clk_register_gate(NULL, desc[n].name, parent,
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  279  					desc[n].flags, base, desc[n].bit_idx,
87e392164ab6c0f Mike Turquette        2014-08-27  280  					0, ctrl->lock);
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  281  		WARN_ON(IS_ERR(ctrl->gates[n]));
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  282  	}
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  283  
a45184099affdd5 Sebastian Hesselbarth 2013-05-11  284  	of_clk_add_provider(np, clk_gating_get_src, ctrl);
f98d007d332b819 Jisheng Zhang         2013-08-23  285  
a97fbc3ee3e2a53 Thierry Reding        2025-10-29  286  	register_syscore(&clk_gate_syscore);
f571053152f6607 Thomas Petazzoni      2014-11-21  287  
f98d007d332b819 Jisheng Zhang         2013-08-23  288  	return;
f98d007d332b819 Jisheng Zhang         2013-08-23 @289  gates_out:

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2026-04-07  3:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02  0:20 [PATCH] clk: mvebu: use kzalloc_flex Rosen Penev
2026-04-03 13:29 ` Brian Masney
2026-04-07  3:59 ` kernel test robot
2026-04-07  3:59 ` kernel test robot

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