[PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex

Rosen Penev posted 1 patch 1 day, 11 hours ago
There is a newer version of this series
drivers/clk/hisilicon/clkdivider-hi6220.c | 26 ++++++++---------------
1 file changed, 9 insertions(+), 17 deletions(-)
[PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
Posted by Rosen Penev 1 day, 11 hours ago
Combine allocations using kzalloc_flex and a flexible array member.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: add missing transformation.
 drivers/clk/hisilicon/clkdivider-hi6220.c | 26 ++++++++---------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisilicon/clkdivider-hi6220.c
index 1787ecefe601..b35c02d3bc05 100644
--- a/drivers/clk/hisilicon/clkdivider-hi6220.c
+++ b/drivers/clk/hisilicon/clkdivider-hi6220.c
@@ -26,8 +26,8 @@
  * @shift:	shift to the divider bit field
  * @width:	width of the divider bit field
  * @mask:	mask for setting divider rate
- * @table:	the div table that the divider supports
  * @lock:	register lock
+ * @->table:	the div table that the divider supports
  */
 struct hi6220_clk_divider {
 	struct clk_hw	hw;
@@ -35,8 +35,8 @@ struct hi6220_clk_divider {
 	u8		shift;
 	u8		width;
 	u32		mask;
-	const struct clk_div_table *table;
 	spinlock_t	*lock;
+	struct clk_div_table table[];
 };

 #define to_hi6220_clk_divider(_hw)	\
@@ -108,24 +108,19 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name,
 	u32 max_div, min_div;
 	int i;

-	/* allocate the divider */
-	div = kzalloc_obj(*div);
-	if (!div)
-		return ERR_PTR(-ENOMEM);
-
 	/* Init the divider table */
 	max_div = div_mask(width) + 1;
 	min_div = 1;

-	table = kzalloc_objs(*table, max_div + 1);
-	if (!table) {
-		kfree(div);
+	/* allocate the divider */
+	div = kzalloc_flex(*div, table, max_div + 1);
+	if (!div)
 		return ERR_PTR(-ENOMEM);
-	}

 	for (i = 0; i < max_div; i++) {
-		table[i].div = min_div + i;
-		table[i].val = table[i].div - 1;
+		table = &div->table[i];
+		table->div = min_div + i;
+		table->val = table->div - 1;
 	}

 	init.name = name;
@@ -141,14 +136,11 @@ struct clk *hi6220_register_clkdiv(struct device *dev, const char *name,
 	div->mask = mask_bit ? BIT(mask_bit) : 0;
 	div->lock = lock;
 	div->hw.init = &init;
-	div->table = table;

 	/* register the clock */
 	clk = clk_register(dev, &div->hw);
-	if (IS_ERR(clk)) {
-		kfree(table);
+	if (IS_ERR(clk))
 		kfree(div);
-	}

 	return clk;
 }
--
2.53.0
Re: [PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
Posted by kernel test robot 10 hours ago
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-20260330]
[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-hisilicon-clkdivider-hi6220-use-kzalloc_flex/20260331-195943
base:   https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next
patch link:    https://lore.kernel.org/r/20260330210217.11168-1-rosenp%40gmail.com
patch subject: [PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
config: arm64-randconfig-002-20260401 (https://download.01.org/0day-ci/archive/20260401/202604010519.tShwh1pt-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260401/202604010519.tShwh1pt-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/202604010519.tShwh1pt-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Warning: drivers/clk/hisilicon/clkdivider-hi6220.c:39 struct member 'table' not described in 'hi6220_clk_divider'
>> Warning: drivers/clk/hisilicon/clkdivider-hi6220.c:39 struct member 'table' not described in 'hi6220_clk_divider'

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
Posted by Brian Masney 18 hours ago
On Mon, Mar 30, 2026 at 02:02:17PM -0700, Rosen Penev wrote:
> Combine allocations using kzalloc_flex and a flexible array member.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  v2: add missing transformation.
>  drivers/clk/hisilicon/clkdivider-hi6220.c | 26 ++++++++---------------
>  1 file changed, 9 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisilicon/clkdivider-hi6220.c
> index 1787ecefe601..b35c02d3bc05 100644
> --- a/drivers/clk/hisilicon/clkdivider-hi6220.c
> +++ b/drivers/clk/hisilicon/clkdivider-hi6220.c
> @@ -26,8 +26,8 @@
>   * @shift:	shift to the divider bit field
>   * @width:	width of the divider bit field
>   * @mask:	mask for setting divider rate
> - * @table:	the div table that the divider supports
>   * @lock:	register lock
> + * @->table:	the div table that the divider supports

Why this change?

Brian
Re: [PATCHv2] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
Posted by Rosen Penev 10 hours ago
On Tue, Mar 31, 2026 at 7:12 AM Brian Masney <bmasney@redhat.com> wrote:
>
> On Mon, Mar 30, 2026 at 02:02:17PM -0700, Rosen Penev wrote:
> > Combine allocations using kzalloc_flex and a flexible array member.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> >  v2: add missing transformation.
> >  drivers/clk/hisilicon/clkdivider-hi6220.c | 26 ++++++++---------------
> >  1 file changed, 9 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/clk/hisilicon/clkdivider-hi6220.c b/drivers/clk/hisilicon/clkdivider-hi6220.c
> > index 1787ecefe601..b35c02d3bc05 100644
> > --- a/drivers/clk/hisilicon/clkdivider-hi6220.c
> > +++ b/drivers/clk/hisilicon/clkdivider-hi6220.c
> > @@ -26,8 +26,8 @@
> >   * @shift:   shift to the divider bit field
> >   * @width:   width of the divider bit field
> >   * @mask:    mask for setting divider rate
> > - * @table:   the div table that the divider supports
> >   * @lock:    register lock
> > + * @->table: the div table that the divider supports
>
> Why this change?
Guess I monkey fingered this in vim... I just wanted ddjp
>
> Brian
>