Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66e98466 authored by Colin Ian King's avatar Colin Ian King Committed by Greg Kroah-Hartman
Browse files

clk: uniphier: Fix potential infinite loop



[ Upstream commit f6b1340dc751a6caa2a0567b667d0f4f4172cd58 ]

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: 734d82f4 ("clk: uniphier: add core support code for UniPhier clock driver")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Reviewed-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Link: https://lore.kernel.org/r/20210409090104.629722-1-colin.king@canonical.com


Signed-off-by: default avatarStephen Boyd <sboyd@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent d9df68d2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -40,10 +40,10 @@ static int uniphier_clk_mux_set_parent(struct clk_hw *hw, u8 index)
static u8 uniphier_clk_mux_get_parent(struct clk_hw *hw)
{
	struct uniphier_clk_mux *mux = to_uniphier_clk_mux(hw);
	int num_parents = clk_hw_get_num_parents(hw);
	unsigned int num_parents = clk_hw_get_num_parents(hw);
	int ret;
	unsigned int val;
	u8 i;
	unsigned int i;

	ret = regmap_read(mux->regmap, mux->reg, &val);
	if (ret)