spi: work around clang bug in SPI_BPW_RANGE_MASK()
PATCH v3 1/1 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 the implementation to use the GENMASK() macro that does what we want here but does not have a problem with the shift count overflow.
---
v3: use GENMASK() instead of open-coding it
v2: add a code comment
--- include/linux/spi/spi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/spi/spi.h +1 -2
@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)/* limits on transfer speed */ u32 min_speed_hz;
Signature · 1 line
2.20.0
Hi Arnd,
Quoted 8 lines · Arnd Bergmann
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), ^~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
Change the implementation to use the
GENMASK()macro that does what we want here but does not have a problem with the shift count overflow.Signed-off-by Arnd Bergmann <[email protected]>
Thanks for your patch!
include/linux/spi/spi.h struct spi_controller { · line 447
Quoted 9 lines
include/linux/spi/spi.h +1
-2@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)
Shouldn't that be GENMASK((max) - 1, (min) - 1)?
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Mark Brown
maintainerApplied "spi: work around clang bug in SPI_BPW_RANGE_MASK()" to the spi tree
In reply to Arnd BergmannThe patch
spi: work around clang bug in SPI_BPW_RANGE_MASK()
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
eefffb42f6659c9510105f3e4ebf2a8499d56936Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <[email protected]>
Date: Thu, 7 Mar 2019 16:54:21 +0100
Subject: [PATCH] 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 the implementation to use the GENMASK() macro that does what we want here but does not have a problem with the shift count overflow.
--- include/linux/spi/spi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/spi/spi.h +1 -2
@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)/* limits on transfer speed */ u32 min_speed_hz;
Signature · 1 line
2.20.1
Re: Applied "spi: work around clang bug in SPI_BPW_RANGE_MASK()" to the spi tree
Hi Mark,
Quoted 56 lines · Mark Brown
The patch
spi: work around clang bug in
SPI_BPW_RANGE_MASK()has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
MarkFrom
eefffb42f6659c9510105f3e4ebf2a8499d56936Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <[email protected]>
Date: Thu, 7 Mar 2019 16:54:21 +0100
Subject: [PATCH] spi: work around clang bug inSPI_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 the implementation to use the
GENMASK()macro that does what we want here but does not have a problem with the shift count overflow.Signed-off-by Arnd Bergmann <[email protected]>Signed-off-by Mark Brown <[email protected]>--- include/linux/spi/spi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)include/linux/spi/spi.h +0
-0
include/linux/spi/spi.h struct spi_controller { · line 447
Quoted 6 lines
include/linux/spi/spi.h +1
-2@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)
This is not correct: GENMASK() order is from msb to lsb. So it should it:
+#define SPI_BPW_RANGE_MASK(min, max) GENMASK((max) - 1, (min) - 1)
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: Applied "spi: work around clang bug in SPI_BPW_RANGE_MASK()" to the spi tree
Quoted 8 lines · Geert Uytterhoeven
include/linux/spi/spi.h struct spi_controller { · line 447
Quoted 3 lines
include/linux/spi/spi.h +1
-2-#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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)This is not correct:
GENMASK()order is from msb to lsb. So it should it:+#define
SPI_BPW_RANGE_MASK(min, max)GENMASK((max) - 1, (min) - 1)
Sorry about the mess, I've sent a fixup now.
Arnd
Mark Brown
maintainerApplied "spi: work around clang bug in SPI_BPW_RANGE_MASK()" to the spi tree
In reply to Arnd BergmannThe patch
spi: work around clang bug in SPI_BPW_RANGE_MASK()
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
eefffb42f6659c9510105f3e4ebf2a8499d56936Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <[email protected]>
Date: Thu, 7 Mar 2019 16:54:21 +0100
Subject: [PATCH] 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 the implementation to use the GENMASK() macro that does what we want here but does not have a problem with the shift count overflow.
--- include/linux/spi/spi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/spi/spi.h +1 -2
@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)/* limits on transfer speed */ u32 min_speed_hz;
Signature · 1 line
2.20.1
Mark Brown
maintainerApplied "spi: work around clang bug in SPI_BPW_RANGE_MASK()" to the spi tree
In reply to Arnd BergmannThe patch
spi: work around clang bug in SPI_BPW_RANGE_MASK()
has been applied to the spi tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark
Quoted 1 line
From
eefffb42f6659c9510105f3e4ebf2a8499d56936Mon Sep 17 00:00:00 2001
From: Arnd Bergmann <[email protected]>
Date: Thu, 7 Mar 2019 16:54:21 +0100
Subject: [PATCH] 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 the implementation to use the GENMASK() macro that does what we want here but does not have a problem with the shift count overflow.
--- include/linux/spi/spi.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
include/linux/spi/spi.h +1 -2
@@ -444,8 +444,7 @@ 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)) +#define SPI_BPW_RANGE_MASK (min, max) GENMASK((min) - 1, (max) - 1)/* limits on transfer speed */ u32 min_speed_hz;
Signature · 1 line
2.20.1