spi: fix undefined behaviour in SPI_BPW_RANGE_MASK
authorStephen Warren <swarren@nvidia.com>
Thu, 30 May 2013 15:59:39 +0000 (09:59 -0600)
committerMark Brown <broonie@linaro.org>
Sat, 1 Jun 2013 18:46:16 +0000 (19:46 +0100)
commit4dd9572abc224019a042b662fb0eececca283cb9
tree920636df3ca9198c43fd89973703b6e177cb27cc
parent6051426fd0538eac4e28c55a08e4f4fb1c709b65
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>
include/linux/spi/spi.h