浏览代码

gpio: mcp23s08: fixed count variable for devicetree probing

Fixed missing increase of count variable for devicetree path in driver
probing.

The gpio-mcp23s08 driver has two paths for getting the platform
registration information. One for the classic platform initialization
and one for openfirmware devicetree based initialization. The devicetree
based path is missing the increase of the count variable, which results
in the count variable to become negative in the later use, where it is
decreased. The count variable is used as an index into a vector. This
results in accessing invalid memory space and can result in an exception.

Tested this with an AM3352 SoC with two mcp23s17 on two chip selects as
well as on a shared chip select.

Signed-off-by: Michael Stickel <ms@mycable.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Michael Stickel 11 年之前
父节点
当前提交
3e3bed913e
共有 1 个文件被更改,包括 10 次插入1 次删除
  1. 10 1
      drivers/gpio/gpio-mcp23s08.c

+ 10 - 1
drivers/gpio/gpio-mcp23s08.c

@@ -895,8 +895,13 @@ static int mcp23s08_probe(struct spi_device *spi)
 			return -ENODEV;
 			return -ENODEV;
 		}
 		}
 
 
-		for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++)
+		for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {
 			pullups[addr] = 0;
 			pullups[addr] = 0;
+			if (spi_present_mask & (1 << addr))
+				chips++;
+		}
+		if (!chips)
+			return -ENODEV;
 	} else {
 	} else {
 		type = spi_get_device_id(spi)->driver_data;
 		type = spi_get_device_id(spi)->driver_data;
 		pdata = dev_get_platdata(&spi->dev);
 		pdata = dev_get_platdata(&spi->dev);
@@ -935,6 +940,10 @@ static int mcp23s08_probe(struct spi_device *spi)
 		if (!(spi_present_mask & (1 << addr)))
 		if (!(spi_present_mask & (1 << addr)))
 			continue;
 			continue;
 		chips--;
 		chips--;
+		if (chips < 0) {
+			dev_err(&spi->dev, "FATAL: invalid negative chip id\n");
+			goto fail;
+		}
 		data->mcp[addr] = &data->chip[chips];
 		data->mcp[addr] = &data->chip[chips];
 		status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
 		status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
 					    0x40 | (addr << 1), type, base,
 					    0x40 | (addr << 1), type, base,