Skip to content

Commit 4d29a6d

Browse files
Will McVickergregkh
Will McVicker
authored andcommitted
clk: samsung: Fix UBSAN panic in samsung_clk_init()
[ Upstream commit d19d7345a7bcdb083b65568a11b11adffe0687af ] With UBSAN_ARRAY_BOUNDS=y, I'm hitting the below panic due to dereferencing `ctx->clk_data.hws` before setting `ctx->clk_data.num = nr_clks`. Move that up to fix the crash. UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP <snip> Call trace: samsung_clk_init+0x110/0x124 (P) samsung_clk_init+0x48/0x124 (L) samsung_cmu_register_one+0x3c/0xa0 exynos_arm64_register_cmu+0x54/0x64 __gs101_cmu_top_of_clk_init_declare+0x28/0x60 ... Fixes: e620a1e ("drivers/clk: convert VL struct to struct_size") Signed-off-by: Will McVicker <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent b07398e commit 4d29a6d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/clk/samsung/clk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ struct samsung_clk_provider * __init samsung_clk_init(struct device *dev,
7474
if (!ctx)
7575
panic("could not allocate clock provider context.\n");
7676

77+
ctx->clk_data.num = nr_clks;
7778
for (i = 0; i < nr_clks; ++i)
7879
ctx->clk_data.hws[i] = ERR_PTR(-ENOENT);
7980

8081
ctx->dev = dev;
8182
ctx->reg_base = base;
82-
ctx->clk_data.num = nr_clks;
8383
spin_lock_init(&ctx->lock);
8484

8585
return ctx;

0 commit comments

Comments
 (0)