* [PATCH] clk: nuvoton: ma35d1-divider: simplify allocation
@ 2026-03-17 0:32 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-03-17 0:32 UTC (permalink / raw)
To: linux-clk
Cc: Jacky Huang, Shan-Chun Hung, Michael Turquette, Stephen Boyd,
moderated list:ARM/NUVOTON MA35 ARCHITECTURE, open list
Use a flexible array member instead of kcalloc + pointer that is not
actually const.
Simplifies allocation slightly.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/nuvoton/clk-ma35d1-divider.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/drivers/clk/nuvoton/clk-ma35d1-divider.c b/drivers/clk/nuvoton/clk-ma35d1-divider.c
index e992e7c30341..6eaca5b35dd8 100644
--- a/drivers/clk/nuvoton/clk-ma35d1-divider.c
+++ b/drivers/clk/nuvoton/clk-ma35d1-divider.c
@@ -17,9 +17,9 @@ struct ma35d1_adc_clk_div {
u8 shift;
u8 width;
u32 mask;
- const struct clk_div_table *table;
/* protects concurrent access to clock divider registers */
spinlock_t *lock;
+ struct clk_div_table table[];
};
static inline struct ma35d1_adc_clk_div *to_ma35d1_adc_clk_div(struct clk_hw *_hw)
@@ -83,30 +83,25 @@ struct clk_hw *ma35d1_reg_adc_clkdiv(struct device *dev, const char *name,
{
struct ma35d1_adc_clk_div *div;
struct clk_init_data init;
- struct clk_div_table *table;
struct clk_parent_data pdata = { .index = 0 };
u32 max_div, min_div;
struct clk_hw *hw;
int ret;
int i;
- div = devm_kzalloc(dev, sizeof(*div), GFP_KERNEL);
- if (!div)
- return ERR_PTR(-ENOMEM);
-
max_div = clk_div_mask(width) + 1;
min_div = 1;
- table = devm_kcalloc(dev, max_div + 1, sizeof(*table), GFP_KERNEL);
- if (!table)
+ div = devm_kzalloc(dev, struct_size(div, table, max_div + 1), GFP_KERNEL);
+ if (!div)
return ERR_PTR(-ENOMEM);
for (i = 0; i < max_div; i++) {
- table[i].val = min_div + i;
- table[i].div = 2 * table[i].val;
+ div->table[i].val = min_div + i;
+ div->table[i].div = 2 * div->table[i].val;
}
- table[max_div].val = 0;
- table[max_div].div = 0;
+ div->table[max_div].val = 0;
+ div->table[max_div].div = 0;
memset(&init, 0, sizeof(init));
init.name = name;
@@ -122,7 +117,6 @@ struct clk_hw *ma35d1_reg_adc_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;
hw = &div->hw;
ret = devm_clk_hw_register(dev, hw);
--
2.53.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-03-17 0:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-17 0:32 [PATCH] clk: nuvoton: ma35d1-divider: simplify allocation Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox