[PATCH 09/11] clk: bm1880: Size .hws by the highest clock id
Ben Cressey
ben at cressey.dev
Thu Dec 3 16:15:47 PST 2026
bm1880_clk_probe() sizes hws[] by the sum of the five clock tables, but
the array is indexed by clock id. The sum is 68 while the ids in the
tables run from 1 to 68. BM1880_CLK_AXI6 is stored one element past the
end of hws[], which CONFIG_UBSAN_BOUNDS can report, and
of_clk_hw_onecell_get() rejects its index.
Size hws[] by the highest clock id plus one. Keep that count in the
driver rather than use BM1880_NR_CLKS from the binding header, as in
commit 26ec588063d9 ("clk: nuvoton: ma35d1: Keep the clock count in the
driver").
Found by an LLM-assisted review of __counted_by users.
Fixes: 1ab4601da55b ("clk: Add common clock driver for BM1880 SoC")
Cc: stable at vger.kernel.org
Signed-off-by: Ben Cressey <ben at cressey.dev>
---
drivers/clk/clk-bm1880.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/clk/clk-bm1880.c b/drivers/clk/clk-bm1880.c
index da8ff672ee0f9..dc13d90bdd919 100644
--- a/drivers/clk/clk-bm1880.c
+++ b/drivers/clk/clk-bm1880.c
@@ -53,6 +53,8 @@
#define BM1880_CLK_DIV27 0xac
#define BM1880_CLK_DIV28 0xb0
+#define BM1880_CLK_COUNT (BM1880_CLK_AXI6 + 1)
+
#define to_bm1880_pll_clk(_hw) container_of(_hw, struct bm1880_pll_hw_clock, hw)
#define to_bm1880_div_clk(_hw) container_of(_hw, struct bm1880_div_hw_clock, hw)
@@ -883,11 +885,7 @@ static int bm1880_clk_probe(struct platform_device *pdev)
if (IS_ERR(sys_base))
return PTR_ERR(sys_base);
- num_clks = ARRAY_SIZE(bm1880_pll_clks) +
- ARRAY_SIZE(bm1880_div_clks) +
- ARRAY_SIZE(bm1880_mux_clks) +
- ARRAY_SIZE(bm1880_composite_clks) +
- ARRAY_SIZE(bm1880_gate_clks);
+ num_clks = BM1880_CLK_COUNT;
clk_data = devm_kzalloc_flex(dev, *clk_data, hw_data.hws, num_clks);
if (!clk_data)
--
2.56.0
More information about the linux-arm-kernel
mailing list