[PATCH 01/11] clk: anlogic: Assign .num before accessing .hws
Ben Cressey
ben at cressey.dev
Thu Dec 3 16:15:39 PST 2026
hws[] is annotated with __counted_by(num), but dr1_cru_clk_register()
fills it before it sets num. With Clang 20 and 21, devm_kzalloc_flex()
leaves num at zero. CONFIG_UBSAN_BOUNDS then reports the accesses and
CONFIG_UBSAN_TRAP makes the first one trap during probe.
Set num right after the allocation.
Found by an LLM-assisted check of __counted_by users.
Fixes: c4e2f5e69ba4 ("clk: anlogic: add cru support for Anlogic DR1V90 SoC")
Signed-off-by: Ben Cressey <ben at cressey.dev>
---
drivers/clk/anlogic/cru_dr1.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/anlogic/cru_dr1.c b/drivers/clk/anlogic/cru_dr1.c
index 478a52d5fa36c..b4ab385455e8b 100644
--- a/drivers/clk/anlogic/cru_dr1.c
+++ b/drivers/clk/anlogic/cru_dr1.c
@@ -187,6 +187,8 @@ int dr1_cru_clk_register(struct device *dev, void __iomem *base,
if (!priv)
return -ENOMEM;
+ priv->num = nr_clks;
+
for (i = 0; i < nr_clks; i++) {
const struct cru_clk *clk = &clks[i];
@@ -200,8 +202,6 @@ int dr1_cru_clk_register(struct device *dev, void __iomem *base,
priv->hws[i] = clk->hw;
}
- priv->num = nr_clks;
-
ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, priv);
if (ret)
dev_err(dev, "failed to add clock hardware provider\n");
--
2.56.0
More information about the linux-arm-kernel
mailing list