diff options
Diffstat (limited to 'drivers/gpio/gpio-mcp23s08.c')
-rw-r--r-- | drivers/gpio/gpio-mcp23s08.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c index 3d53fd6880d1..fe7c0e211f9a 100644 --- a/drivers/gpio/gpio-mcp23s08.c +++ b/drivers/gpio/gpio-mcp23s08.c | |||
@@ -714,7 +714,7 @@ fail: | |||
714 | 714 | ||
715 | #ifdef CONFIG_OF | 715 | #ifdef CONFIG_OF |
716 | #ifdef CONFIG_SPI_MASTER | 716 | #ifdef CONFIG_SPI_MASTER |
717 | static struct of_device_id mcp23s08_spi_of_match[] = { | 717 | static const struct of_device_id mcp23s08_spi_of_match[] = { |
718 | { | 718 | { |
719 | .compatible = "microchip,mcp23s08", | 719 | .compatible = "microchip,mcp23s08", |
720 | .data = (void *) MCP_TYPE_S08, | 720 | .data = (void *) MCP_TYPE_S08, |
@@ -738,7 +738,7 @@ MODULE_DEVICE_TABLE(of, mcp23s08_spi_of_match); | |||
738 | #endif | 738 | #endif |
739 | 739 | ||
740 | #if IS_ENABLED(CONFIG_I2C) | 740 | #if IS_ENABLED(CONFIG_I2C) |
741 | static struct of_device_id mcp23s08_i2c_of_match[] = { | 741 | static const struct of_device_id mcp23s08_i2c_of_match[] = { |
742 | { | 742 | { |
743 | .compatible = "microchip,mcp23008", | 743 | .compatible = "microchip,mcp23008", |
744 | .data = (void *) MCP_TYPE_008, | 744 | .data = (void *) MCP_TYPE_008, |
@@ -867,7 +867,7 @@ static int mcp23s08_probe(struct spi_device *spi) | |||
867 | { | 867 | { |
868 | struct mcp23s08_platform_data *pdata; | 868 | struct mcp23s08_platform_data *pdata; |
869 | unsigned addr; | 869 | unsigned addr; |
870 | unsigned chips = 0; | 870 | int chips = 0; |
871 | struct mcp23s08_driver_data *data; | 871 | struct mcp23s08_driver_data *data; |
872 | int status, type; | 872 | int status, type; |
873 | unsigned base = -1, | 873 | unsigned base = -1, |
@@ -894,11 +894,14 @@ static int mcp23s08_probe(struct spi_device *spi) | |||
894 | dev_err(&spi->dev, "invalid spi-present-mask\n"); | 894 | dev_err(&spi->dev, "invalid spi-present-mask\n"); |
895 | return -ENODEV; | 895 | return -ENODEV; |
896 | } | 896 | } |
897 | |||
897 | for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { | 898 | for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) { |
898 | if ((spi_present_mask & (1 << addr))) | ||
899 | chips++; | ||
900 | pullups[addr] = 0; | 899 | pullups[addr] = 0; |
900 | if (spi_present_mask & (1 << addr)) | ||
901 | chips++; | ||
901 | } | 902 | } |
903 | if (!chips) | ||
904 | return -ENODEV; | ||
902 | } else { | 905 | } else { |
903 | type = spi_get_device_id(spi)->driver_data; | 906 | type = spi_get_device_id(spi)->driver_data; |
904 | pdata = dev_get_platdata(&spi->dev); | 907 | pdata = dev_get_platdata(&spi->dev); |
@@ -937,6 +940,10 @@ static int mcp23s08_probe(struct spi_device *spi) | |||
937 | if (!(spi_present_mask & (1 << addr))) | 940 | if (!(spi_present_mask & (1 << addr))) |
938 | continue; | 941 | continue; |
939 | chips--; | 942 | chips--; |
943 | if (chips < 0) { | ||
944 | dev_err(&spi->dev, "FATAL: invalid negative chip id\n"); | ||
945 | goto fail; | ||
946 | } | ||
940 | data->mcp[addr] = &data->chip[chips]; | 947 | data->mcp[addr] = &data->chip[chips]; |
941 | status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, | 948 | status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi, |
942 | 0x40 | (addr << 1), type, base, | 949 | 0x40 | (addr << 1), type, base, |