Skip to content

Commit 7578847

Browse files
Dan Carpenterjic23
authored andcommitted
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: 6d96588 ("iio: adc: mcp3911: add support for oversampling ratio") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Marcus Folkesson <[email protected]> Link: https://lore.kernel.org/r/YzFsjY3xLHUQMjVr@kili Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 0dec4d2 commit 7578847

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/iio/adc/mcp3911.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static int mcp3911_write_raw(struct iio_dev *indio_dev,
248248
break;
249249

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

0 commit comments

Comments
 (0)