Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
clk: stm32: Fix out-by-one error path in the index lookup
Browse files Browse the repository at this point in the history
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: Dan Carpenter <[email protected]>
Signed-off-by: Daniel Thompson <[email protected]>
Acked-by: Maxime Coquelin <[email protected]>
Fixes: 358bdf8 ("clk: stm32: Add clock driver for STM32F4[23]xxx devices")
Signed-off-by: Stephen Boyd <[email protected]>
  • Loading branch information
daniel-thompson authored and bebarino committed Jul 2, 2015
1 parent 69916d9 commit 15ab382
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/clk/clk-stm32f4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 15ab382

Please sign in to comment.