Re: [PATCH v2 1/4] i2c: octeon: Fix infinite loop in clock divisor calculation
From: Paul Cercueil
Date: Mon Nov 23 2026 - 07:58:30 EST
Hi Robert, Andi,
Le vendredi 13 novembre 2026 à 14:41 +0100, Paul Cercueil a écrit :
> From: Tanmay Jagdale <tanmay@xxxxxxxxxxx>
>
> When mdiv_min is unsigned, the signed mdiv_idx variable is cast to
> unsigned as well in the inner loop condition comparison, leading to an
> infinite loop.
>
> Fixes: 03240f826b02 ("i2c: thunderx: Support for High speed mode")
I get only one complaint from Sashiko on this patchset, which is that the Fixes:
tag should actually point to 114c69f4be3f ("i2c: thunderx: Clock
divisor logic changes").
Do you want a v3 with that addressed?
Cheers,
-Paul
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Tanmay Jagdale <tanmay@xxxxxxxxxxx>
> Co-developed-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
> Signed-off-by: Paul Cercueil <paul.cercueil@xxxxxxxxxxx>
>
> ---
>
> v2: New patch
> ---
> drivers/i2c/busses/i2c-octeon-core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-
> octeon-core.c
> index 93a49e4637ec..85e18ca2410e 100644
> --- a/drivers/i2c/busses/i2c-octeon-core.c
> +++ b/drivers/i2c/busses/i2c-octeon-core.c
> @@ -823,14 +823,14 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct
> i2c_msg *msgs, int num)
> /* calculate and set clock divisors */
> void octeon_i2c_set_clock(struct octeon_i2c *i2c)
> {
> - int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff;
> + int tclk, thp_base, inc, thp_idx, mdiv_idx, mdiv_min, ndiv_idx,
> foscl, diff;
> bool is_plat_otx2;
> /*
> * Find divisors to produce target frequency, start with large delta
> * to cover wider range of divisors, note thp = TCLK half period and
> * ds is OSCL output frequency divisor.
> */
> - unsigned int thp, mdiv_min, mdiv = 2, ndiv = 0, ds = 10;
> + unsigned int thp, mdiv = 2, ndiv = 0, ds = 10;
> unsigned int delta_hz = INITIAL_DELTA_HZ;
>
> is_plat_otx2 = octeon_i2c_is_otx2(to_pci_dev(i2c->dev));