Re: [PATCH][V2] clk: uniphier: Fix potential infinite loop
Quoting Colin King (2021-04-09 02:01:04) > From: Colin Ian King > > 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 > --- Applied to clk-next
Re: [PATCH][V2] clk: uniphier: Fix potential infinite loop
On Fri, Apr 9, 2021 at 6:01 PM Colin King wrote: > > From: Colin Ian King > > 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 > --- > > V2: Make num_parents an unsigned int to match return type of > clk_hw_get_num_parents(). Reviewed-by: Masahiro Yamada > --- > drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c > b/drivers/clk/uniphier/clk-uniphier-mux.c > index 462c84321b2d..1998e9d4cfc0 100644 > --- a/drivers/clk/uniphier/clk-uniphier-mux.c > +++ b/drivers/clk/uniphier/clk-uniphier-mux.c > @@ -31,10 +31,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, ); > if (ret) > -- > 2.30.2 > -- Best Regards Masahiro Yamada
[PATCH][V2] clk: uniphier: Fix potential infinite loop
From: Colin Ian King 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 --- V2: Make num_parents an unsigned int to match return type of clk_hw_get_num_parents(). --- drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c index 462c84321b2d..1998e9d4cfc0 100644 --- a/drivers/clk/uniphier/clk-uniphier-mux.c +++ b/drivers/clk/uniphier/clk-uniphier-mux.c @@ -31,10 +31,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, ); if (ret) -- 2.30.2
[PATCH][V2] clk: uniphier: Fix potential infinite loop
From: Colin Ian King 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 --- V2: Make num_parents an unsigned int to match return type of clk_hw_get_num_parents(). --- drivers/clk/uniphier/clk-uniphier-mux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/clk/uniphier/clk-uniphier-mux.c b/drivers/clk/uniphier/clk-uniphier-mux.c index 462c84321b2d..1998e9d4cfc0 100644 --- a/drivers/clk/uniphier/clk-uniphier-mux.c +++ b/drivers/clk/uniphier/clk-uniphier-mux.c @@ -31,10 +31,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, ); if (ret) -- 2.30.2