mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
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: 6d965885f4
("iio: adc: mcp3911: add support for oversampling ratio")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Marcus Folkesson <marcus.folkesson@gmail.com>
Link: https://lore.kernel.org/r/YzFsjY3xLHUQMjVr@kili
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
0dec4d2f26
commit
7578847b59
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user