diff options
author | Torsten Fleischer <torfl6749@gmail.com> | 2014-11-07 12:11:58 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-11-08 04:12:57 -0500 |
commit | cfb4bbd8fbed76a6b715916fabeca4597cb38721 (patch) | |
tree | 738d94a5ed02713d5f82c8f2ec8d8df9f7e1437f /drivers/spi | |
parent | d1d81802522ade84128a2c66c0d500e372474dca (diff) |
spi: spi-gpio: Fix compiler warning when building for 64 bit systems
The assignment of SPI_GPIO_NO_CHIPSELECT to cs_gpios[0] causes the following
compiler warning, when building for 64 bit systems:
"warning: overflow in implicit constant conversion [-Woverflow]".
This is because the SPI_GPIO_NO_CHIPSELECT flag is a '-1' type casted to
unsigned long and cs_gpios is of the type int.
Furthermore the chip select's GPIO number is locally stored as unsigned int
and compared with SPI_GPIO_NO_CHIPSELECT. Thus the result of the comparison
is always false, if unsigned long and unsigned int have a different size.
As part of the fix this patch adds a check for the device tree's cs-gpios
property.
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Torsten Fleischer <torfl6749@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-gpio.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index f0492c99d145..4b600d4f8548 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -48,7 +48,7 @@ struct spi_gpio { | |||
48 | struct spi_bitbang bitbang; | 48 | struct spi_bitbang bitbang; |
49 | struct spi_gpio_platform_data pdata; | 49 | struct spi_gpio_platform_data pdata; |
50 | struct platform_device *pdev; | 50 | struct platform_device *pdev; |
51 | int cs_gpios[0]; | 51 | unsigned long cs_gpios[0]; |
52 | }; | 52 | }; |
53 | 53 | ||
54 | /*----------------------------------------------------------------------*/ | 54 | /*----------------------------------------------------------------------*/ |
@@ -220,7 +220,7 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, | |||
220 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) | 220 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) |
221 | { | 221 | { |
222 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 222 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
223 | unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; | 223 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; |
224 | 224 | ||
225 | /* set initial clock polarity */ | 225 | /* set initial clock polarity */ |
226 | if (is_active) | 226 | if (is_active) |
@@ -234,7 +234,7 @@ static void spi_gpio_chipselect(struct spi_device *spi, int is_active) | |||
234 | 234 | ||
235 | static int spi_gpio_setup(struct spi_device *spi) | 235 | static int spi_gpio_setup(struct spi_device *spi) |
236 | { | 236 | { |
237 | unsigned int cs; | 237 | unsigned long cs; |
238 | int status = 0; | 238 | int status = 0; |
239 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 239 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
240 | struct device_node *np = spi->master->dev.of_node; | 240 | struct device_node *np = spi->master->dev.of_node; |
@@ -249,7 +249,7 @@ static int spi_gpio_setup(struct spi_device *spi) | |||
249 | /* | 249 | /* |
250 | * ... otherwise, take it from spi->controller_data | 250 | * ... otherwise, take it from spi->controller_data |
251 | */ | 251 | */ |
252 | cs = (unsigned int)(uintptr_t) spi->controller_data; | 252 | cs = (uintptr_t) spi->controller_data; |
253 | } | 253 | } |
254 | 254 | ||
255 | if (!spi->controller_state) { | 255 | if (!spi->controller_state) { |
@@ -277,7 +277,7 @@ static int spi_gpio_setup(struct spi_device *spi) | |||
277 | static void spi_gpio_cleanup(struct spi_device *spi) | 277 | static void spi_gpio_cleanup(struct spi_device *spi) |
278 | { | 278 | { |
279 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 279 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
280 | unsigned int cs = spi_gpio->cs_gpios[spi->chip_select]; | 280 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; |
281 | 281 | ||
282 | if (cs != SPI_GPIO_NO_CHIPSELECT) | 282 | if (cs != SPI_GPIO_NO_CHIPSELECT) |
283 | gpio_free(cs); | 283 | gpio_free(cs); |
@@ -437,7 +437,7 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
437 | return status; | 437 | return status; |
438 | 438 | ||
439 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + | 439 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + |
440 | (sizeof(int) * num_devices)); | 440 | (sizeof(unsigned long) * num_devices)); |
441 | if (!master) { | 441 | if (!master) { |
442 | status = -ENOMEM; | 442 | status = -ENOMEM; |
443 | goto gpio_free; | 443 | goto gpio_free; |
@@ -470,9 +470,15 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
470 | if (!SPI_N_CHIPSEL) | 470 | if (!SPI_N_CHIPSEL) |
471 | spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; | 471 | spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; |
472 | else | 472 | else |
473 | for (i = 0; i < SPI_N_CHIPSEL; i++) | 473 | for (i = 0; i < SPI_N_CHIPSEL; i++) { |
474 | spi_gpio->cs_gpios[i] = | 474 | status = of_get_named_gpio(np, "cs-gpios", i); |
475 | of_get_named_gpio(np, "cs-gpios", i); | 475 | if (status < 0) { |
476 | dev_err(&pdev->dev, | ||
477 | "invalid cs-gpios property\n"); | ||
478 | goto gpio_free; | ||
479 | } | ||
480 | spi_gpio->cs_gpios[i] = status; | ||
481 | } | ||
476 | } | 482 | } |
477 | #endif | 483 | #endif |
478 | 484 | ||