[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20190307121004.1068172-1-arnd@arndb.de>
Date: Thu, 7 Mar 2019 13:09:46 +0100
From: Arnd Bergmann <arnd@...db.de>
To: Mark Brown <broonie@...nel.org>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Arnd Bergmann <arnd@...db.de>,
Boris Brezillon <bbrezillon@...nel.org>,
Marco Felsch <m.felsch@...gutronix.de>,
Linus Walleij <linus.walleij@...aro.org>,
Frieder Schrempf <frieder.schrempf@...eet.de>,
linux-spi@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] [v2] spi: work around clang bug in SPI_BPW_RANGE_MASK()
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.
Link: https://bugs.llvm.org/show_bug.cgi?id=38789
Signed-off-by: Arnd Bergmann <arnd@...db.de>
---
v2: add a code comment
---
include/linux/spi/spi.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 662b336aa2e4..1500745a9835 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -444,8 +444,12 @@ struct spi_controller {
/* bitmask of supported bits_per_word for transfers */
u32 bits_per_word_mask;
#define SPI_BPW_MASK(bits) BIT((bits) - 1)
-#define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1))
-#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min - 1))
+/*
+ * double shift to avoid shifting beyond BITS_PER_LONG, see also
+ * https://bugs.llvm.org/show_bug.cgi?id=38789
+ */
+#define SPI_BIT_MASK(bits) ((BIT((bits) - 1) << 1) - 1)
+#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - (BIT((min) - 1) - 1))
/* limits on transfer speed */
u32 min_speed_hz;
--
2.20.0
Powered by blists - more mailing lists