Re: [PATCH v11 06/12] pwm: imx27: Use 64-bit division macro and function

From: Arnd Bergmann
Date: Fri Mar 20 2020 - 13:10:01 EST


On Fri, Mar 20, 2020 at 2:42 AM Guru Das Srinagesh <gurus@xxxxxxxxxxxxxx> wrote:

> @@ -240,8 +240,7 @@ static int pwm_imx27_apply(struct pwm_chip *chip, struct pwm_device *pwm,
>
> period_cycles /= prescale;
> c = (unsigned long long)period_cycles * state->duty_cycle;
> - do_div(c, state->period);
> - duty_cycles = c;
> + duty_cycles = div64_u64(c, state->period);
>

This change looks fine, but I wonder if the code directly above it

c = clk_get_rate(imx->clk_per);
c *= state->period;
do_div(c, 1000000000);
period_cycles = c;

might run into an overflow when both the clock rate and the period
are large numbers.

Arnd