Skip to content

Commit 5fb33b6

Browse files
AaronDotbebarino
authored andcommitted
clk: clk-loongson2: Fix the number count of clk provider
Since commit 02fb4f0 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access"), the clk provider register is failed. The count of `clks_num` is shown below: for (p = data; p->name; p++) clks_num++; In fact, `clks_num` represents the number of SoC clocks and should be expressed as the maximum value of the clock binding id in use (p->id + 1). Now we fix it to avoid the following error when trying to register a clk provider: [ 13.409595] of_clk_hw_onecell_get: invalid index 17 Cc: stable@vger.kernel.org Cc: Gustavo A. R. Silva <gustavoars@kernel.org> Fixes: 02fb4f0 ("clk: clk-loongson2: Fix potential buffer overflow in flexible-array member access") Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn> Link: https://lore.kernel.org/r/82e43d89a9a6791129cf8ea14f4eeb666cd87be4.1736856470.git.zhoubinbin@loongson.cn Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 590a094 commit 5fb33b6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/clk/clk-loongson2.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int loongson2_clk_probe(struct platform_device *pdev)
294294
return -EINVAL;
295295

296296
for (p = data; p->name; p++)
297-
clks_num++;
297+
clks_num = max(clks_num, p->id + 1);
298298

299299
clp = devm_kzalloc(dev, struct_size(clp, clk_data.hws, clks_num),
300300
GFP_KERNEL);
@@ -309,6 +309,9 @@ static int loongson2_clk_probe(struct platform_device *pdev)
309309
clp->clk_data.num = clks_num;
310310
clp->dev = dev;
311311

312+
/* Avoid returning NULL for unused id */
313+
memset_p((void **)clp->clk_data.hws, ERR_PTR(-ENOENT), clks_num);
314+
312315
for (i = 0; i < clks_num; i++) {
313316
p = &data[i];
314317
switch (p->type) {

0 commit comments

Comments
 (0)