summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2013-05-30 09:59:39 -0600
committerJason Liu <r64343@freescale.com>2013-10-30 09:56:07 +0800
commit42f079b7610d6dc1c13923579f3cce8ac077b1f6 (patch)
treed8dc1a74c9560086390c1c67456b08a262782000 /include
parent06958bcd9afe78bd920d142724e76c9f535aebbd (diff)
spi: fix undefined behaviour in SPI_BPW_RANGE_MASK
The parameters to SPI_BPW_RANGE_MASK() are in the range 1..32. If 32 is used as a parameter, part of the expression is "1 << 32". Since 32 is >= the size of the type in use, such a shift is undefined behaviour. Add macro SPI_BIT_MASK to Implement a special case and thus avoid undefined behaviour. Use this new macro rather than BIT() when implementing SPI_BPW_RANGE_MASK(). This fixes build warnings such as: drivers/spi/spi-gpio.c:446:2: warning: left shift count >= width of type [enabled by default] SPI_BPW_MASK() already avoids this, since its parameter is also in range 1..32, yet it only shifts by up to one less than the input parameter. Reported-by: Fengguang Wu <fengguang.wu@intel.com> Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@linaro.org> Signed-off-by: Huang Shijie <b32955@freescale.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/spi/spi.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 173725622252..3e9479134d9d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -309,7 +309,8 @@ struct spi_master {
/* bitmask of supported bits_per_word for transfers */
u32 bits_per_word_mask;
#define SPI_BPW_MASK(bits) BIT((bits) - 1)
-#define SPI_BPW_RANGE_MASK(min, max) ((BIT(max) - 1) - (BIT(min) - 1))
+#define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0UL : (BIT(bits) - 1))
+#define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min))
/* other constraints relevant to this driver */
u16 flags;