* [PATCHv3] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
@ 2026-04-01 2:35 Rosen Penev
2026-04-01 14:17 ` Brian Masney
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-04-01 2:35 UTC (permalink / raw)
To: linux-clk; +Cc: Michael Turquette, Stephen Boyd, open list
Combine allocations using kzalloc_flex and a flexible array member.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v3: fix wrongly added -> in table comment.
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv3] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex
2026-04-01 2:35 [PATCHv3] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex Rosen Penev
@ 2026-04-01 14:17 ` Brian Masney
0 siblings, 0 replies; 2+ messages in thread
From: Brian Masney @ 2026-04-01 14:17 UTC (permalink / raw)
To: Rosen Penev; +Cc: linux-clk, Michael Turquette, Stephen Boyd, open list
On Tue, Mar 31, 2026 at 07:35:51PM -0700, Rosen Penev wrote:
> Combine allocations using kzalloc_flex and a flexible array member.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Brian Masney <bmasney@redhat.com>
For the future, if someone asks for changes in a previous version, then
be sure to CC them on the next revision.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-01 14:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 2:35 [PATCHv3] clk: hisilicon: clkdivider-hi6220: use kzalloc_flex Rosen Penev
2026-04-01 14:17 ` Brian Masney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox