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

clk: uniphier: Fix potential infinite loop

The for-loop iterates with a u8 loop counter i and compares this
with the loop upper limit of num_parents that is an int type.
There is a potential infinite loop if num_parents is larger than
the u8 loop counter. Fix this by making the loop counter the same
type as num_parents. Also make num_parents an unsigned int to
match the return type of the call to clk_hw_get_num_parents.

Addresses-Coverity: ("Infinite loop")
Fixes: 734d82f4a678 ("clk: uniphier: add core support code for UniPhier clock driver")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Masahiro Yamada <masahiroy@kernel.org>
Link: https://lore.kernel.org/r/20210409090104.629722-1-colin.king@canonical.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Colin Ian King and committed by
Stephen Boyd
f6b1340d a38fd874

+2 -2
+2 -2
drivers/clk/uniphier/clk-uniphier-mux.c
··· 31 31 static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw) 32 32 { 33 33 struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw); 34 - int num_parents = clk_hw_get_num_parents(hw); 34 + unsigned int num_parents = clk_hw_get_num_parents(hw); 35 35 int ret; 36 36 unsigned int val; 37 - u8 i; 37 + unsigned int i; 38 38 39 39 ret = regmap_read(mux->regmap, mux->reg, &val); 40 40 if (ret)