Commit 15ab3827 authored by Daniel Thompson's avatar Daniel Thompson Committed by Stephen Boyd

clk: stm32: Fix out-by-one error path in the index lookup

If stm32f4_rcc_lookup() is called with primary == 0 and secondary == 192
then it will read beyond the end of the table array due to an out-by-one
error in the range check.

In addition to the fixing the inequality we also modify the r.h.s. to
make it even more explicit that we are comparing against the size of
table in bits.
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Acked-by: default avatarMaxime Coquelin <mcoquelin.stm32@gmail.com>
Fixes: 358bdf89 ("clk: stm32: Add clock driver for STM32F4[23]xxx devices")
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
parent 69916d96
......@@ -268,7 +268,7 @@ static int stm32f4_rcc_lookup_clk_idx(u8 primary, u8 secondary)
memcpy(table, stm32f42xx_gate_map, sizeof(table));
/* only bits set in table can be used as indices */
if (WARN_ON(secondary > 8 * sizeof(table) ||
if (WARN_ON(secondary >= BITS_PER_BYTE * sizeof(table) ||
0 == (table[BIT_ULL_WORD(secondary)] &
BIT_ULL_MASK(secondary))))
return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment