* [PATCH RESEND] clk: nuvoton: ma35d1-divider: simplify allocation
@ 2026-09-12 0:23 Rosen Penev
2026-09-14 3:22 ` a0987203069
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-09-12 0:23 UTC (permalink / raw)
To: linux-clk
Cc: Jacky Huang, Shan-Chun Hung, Stephen Boyd, Brian Masney,
Jerome Brunet, 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.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH RESEND] clk: nuvoton: ma35d1-divider: simplify allocation
2026-09-12 0:23 [PATCH RESEND] clk: nuvoton: ma35d1-divider: simplify allocation Rosen Penev
@ 2026-09-14 3:22 ` a0987203069
0 siblings, 0 replies; 2+ messages in thread
From: a0987203069 @ 2026-09-14 3:22 UTC (permalink / raw)
To: linux-clk
Cc: rosenp, Jacky Huang, Shan-Chun Hung, Stephen Boyd, Brian Masney,
Jerome Brunet, linux-arm-kernel, linux-kernel
Hi Rosen,
On Fri, Sep 11, 2026 at 05:23:26PM -0700, Rosen Penev wrote:
> Use a flexible array member instead of kcalloc + pointer that is not
> actually const.
>
> Simplifies allocation slightly.
Thanks for the patch, and sorry for the slow reply.
We're already working on a different fix for this driver internally:
the ADC divider register actually implements a simple closed-form
relationship (rate = parent_rate / (2 * (N + 1))), so building and
scanning a clk_div_table with up to 2^width entries via the generic
divider_recalc_rate()/divider_determine_rate()/divider_get_val()
helpers is unnecessary overhead in the first place -- we're replacing
the table entirely with direct arithmetic in recalc_rate()/
determine_rate()/set_rate() instead of just changing how it's
allocated.
Since our patch removes the table (and the unrelated mask_bit
mechanism, which has an out-of-range shift bug at its only call site)
rather than reshaping it, we won't be adopting this patch, but we do
appreciate you catching the allocation issue. We'll post our fix
shortly for review.
Thanks again,
Joey
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-14 3:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-12 0:23 [PATCH RESEND] clk: nuvoton: ma35d1-divider: simplify allocation Rosen Penev
2026-09-14 3:22 ` a0987203069
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®