Messages in this thread | | | Date | Mon, 6 Apr 2020 17:26:31 -0700 | From | Guru Das Srinagesh <> | Subject | Re: [PATCH v11 04/12] pwm: clps711x: Cast period to u32 before use as divisor |
| |
On Fri, Mar 20, 2020 at 06:11:42PM +0100, Arnd Bergmann wrote: > On Fri, Mar 20, 2020 at 2:41 AM Guru Das Srinagesh <gurus@codeaurora.org> wrote: > > > > Since the PWM framework is switching struct pwm_args.period's datatype > > to u64, prepare for this transition by typecasting it to u32. > > > > Also, since the dividend is still a 32-bit number, any divisor greater > > than UINT_MAX will cause the quotient to be zero, so return 0 in that > > case to efficiently skip the division. > > > > Cc: Alexander Shiyan <shc_work@mail.ru> > > Cc: Arnd Bergmann <arnd@arndb.de> > > > > Signed-off-by: Guru Das Srinagesh <gurus@codeaurora.org> > > Reviewed-by: Arnd Bergmann <arnd@arndb.de>
The stated aim of adding the if condition is to determine when the division operation may be skipped as the quotient would be zero anyway [1]. That said, I think the current if condition is incorrect. The quotient would be zero only when the denominator of the division exceeds (v * 0xf) and not UINT_MAX. In fact, UINT_MAX has no bearing on whether the quotient becomes zero or not.
Therefore, the correct if condition should be:
- return DIV_ROUND_CLOSEST(v * 0xf, pwm->args.period); + if ((u32)pwm->args.period > (v * 0xf)) + return 0; + + return DIV_ROUND_CLOSEST(v * 0xf, (u32)pwm->args.period);
What do you think?
[1] https://www.spinics.net/lists/linux-pwm/msg11908.html
Thank you.
Guru Das.
| |