Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: uniphier: fix memory overrun bug

The first loop of this "for" statement writes memory beyond the
allocated clk_hw_onecell_data.

It should be:
for (clk_num--; clk_num >= 0; clk_num--)
...

Or more simply:
while (--clk_num >= 0)
...

Fixes: 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Masahiro Yamada and committed by
Stephen Boyd
7d36b9c1 d3397484

+1 -1
+1 -1
drivers/clk/uniphier/clk-uniphier-core.c
··· 79 79 hw_data->num = clk_num; 80 80 81 81 /* avoid returning NULL for unused idx */ 82 - for (; clk_num >= 0; clk_num--) 82 + while (--clk_num >= 0) 83 83 hw_data->hws[clk_num] = ERR_PTR(-EINVAL); 84 84 85 85 for (p = data; p->name; p++) {