[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAK8P3a1B7PakyYxT88v5Du+5CQZNCiA5xJ_Q4DtSSsGaM7FCnA@mail.gmail.com>
Date: Thu, 7 Mar 2019 14:22:59 +0100
From: Arnd Bergmann <arnd@...db.de>
To: Rasmus Villemoes <linux@...musvillemoes.dk>
Cc: Mark Brown <broonie@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Boris Brezillon <bbrezillon@...nel.org>,
Marco Felsch <m.felsch@...gutronix.de>,
Frieder Schrempf <frieder.schrempf@...eet.de>,
Linus Walleij <linus.walleij@...aro.org>,
linux-spi <linux-spi@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] spi: work around clang bug in SPI_BPW_RANGE_MASK()
On Thu, Mar 7, 2019 at 2:09 PM Rasmus Villemoes
<linux@...musvillemoes.dk> wrote:
>
> On 07/03/2019 11.56, Arnd Bergmann wrote:
> > Clang-8 evaluates both sides of a ?: expression to check for
> > valid arithmetic even in the side that is never taken. This
> > results in a build warning:
> >
> > drivers/spi/spi-sh-msiof.c:1052:24: error: shift count >= width of type [-Werror,-Wshift-count-overflow]
> > .bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32),
> > ^~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Change it to shift one less than we want, and then shift one
> > more bit afterwards. This should give the correct result for
> > all valid input, since it has to be in the range 1..32 anyway.
>
> Why not use GENMASK which is provided by the same header that #defines BIT?
It might be an options, but
- I had not thought of it
- It looks like it would have the same problem with shifting right by
32 bits (?)
- it seems to have slightly different semantics from SPI_BPW_RANGE_MASK(),
counting the bits from 0 instead of 1.
I tried this version now, which doesn't produce any warnings as far as I can
tell, but I'm not convinced that it's actually correct. Can you have a look?
#define SPI_BPW_RANGE_MASK(min, max) GENMASK((min) - 1, (max) - 1)
Arnd
Powered by blists - more mailing lists