Commit 7578847b authored by Dan Carpenter's avatar Dan Carpenter Committed by Jonathan Cameron
Browse files

iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug



This code uses sizeof() instead of ARRAY_SIZE() so it reads beyond the
end of the mcp3911_osr_table[] array.

Fixes: 6d965885 ("iio: adc: mcp3911: add support for oversampling ratio")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarMarcus Folkesson <marcus.folkesson@gmail.com>
Link: https://lore.kernel.org/r/YzFsjY3xLHUQMjVr@kili


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 0dec4d2f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
		break;

	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
		for (int i = 0; i < sizeof(mcp3911_osr_table); i++) {
		for (int i = 0; i < ARRAY_SIZE(mcp3911_osr_table); i++) {
			if (val == mcp3911_osr_table[i]) {
				val = FIELD_PREP(MCP3911_CONFIG_OSR, i);
				ret = mcp3911_update(adc, MCP3911_REG_CONFIG, MCP3911_CONFIG_OSR,