Arnd Bergmann
2017-Sep-06 20:11 UTC
[Nouveau] [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
On Wed, Sep 6, 2017 at 4:20 PM, Karol Herbst <karolherbst at gmail.com> wrote:>> In this instance, I think using multiplication is more intuitive >> than '&&', so I'm adding a comparison to zero instead to shut up >> the warning. To further improve readability, I also make the >> error case indented and leave the normal case as the final 'return' >> statement. >> > > I think to make perfectly clear why this check is done, we simply > should precompute the denominator and do something like this: > > int denominator = M * P > if (denominator == 0) > return 0; > return sclk * N / denominator; > > but with a better name for "denominator".I don't know what M and P actually are in this function, so I couldn't come up with a much better name either, how about simply 'divisor'?> I even imagine, that there > are some macros in the kernel for dealing with something like this > already, so that we could do instead: > > return AWESOME_DIV_MACRO(sclk * N, M * P)I don't think that exists, the behavior for divide-by-zero really depends a lot on the context, and returning zero is probably often not a good solution. Arnd
Karol Herbst
2017-Sep-06 20:15 UTC
[Nouveau] [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
On Wed, Sep 6, 2017 at 10:11 PM, Arnd Bergmann <arnd at arndb.de> wrote:> On Wed, Sep 6, 2017 at 4:20 PM, Karol Herbst <karolherbst at gmail.com> wrote: >>> In this instance, I think using multiplication is more intuitive >>> than '&&', so I'm adding a comparison to zero instead to shut up >>> the warning. To further improve readability, I also make the >>> error case indented and leave the normal case as the final 'return' >>> statement. >>> >> >> I think to make perfectly clear why this check is done, we simply >> should precompute the denominator and do something like this: >> >> int denominator = M * P >> if (denominator == 0) >> return 0; >> return sclk * N / denominator; >> >> but with a better name for "denominator". > > I don't know what M and P actually are in this function, so I couldn't > come up with a much better name either, how about simply 'divisor'? >what about "MP"? M and P are simply dividers for the PLL configuration and there are two of them. I think "P" is the post divider.>> I even imagine, that there >> are some macros in the kernel for dealing with something like this >> already, so that we could do instead: >> >> return AWESOME_DIV_MACRO(sclk * N, M * P) > > I don't think that exists, the behavior for divide-by-zero really > depends a lot on the context, and returning zero is probably > often not a good solution. > > Arnd
Arnd Bergmann
2017-Sep-06 21:40 UTC
[Nouveau] [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
On Wed, Sep 6, 2017 at 10:15 PM, Karol Herbst <karolherbst at gmail.com> wrote:> On Wed, Sep 6, 2017 at 10:11 PM, Arnd Bergmann <arnd at arndb.de> wrote: >>> but with a better name for "denominator". >> >> I don't know what M and P actually are in this function, so I couldn't >> come up with a much better name either, how about simply 'divisor'? >> > > what about "MP"? M and P are simply dividers for the PLL configuration > and there are two of them. I think "P" is the post divider. >Fine with me. That was actually what I initially did after your reply and then changed it to divisor. I've changed it back now and sent the new version. Arnd
Maybe Matching Threads
- [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
- [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
- [PATCH] [RESEND] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
- [PATCH] [RESEND v2] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning
- [PATCH] [v2] drm/nouveau/clk: fix gcc-7 -Wint-in-bool-context warning