iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug
Subsystems (3)
PATCH 1/1 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 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")
Signed-off-by Dan Carpenter <[email protected]>
--- drivers/iio/adc/mcp3911.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/mcp3911.c +1 -1
@@ -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,
Signature · 1 line
2.35.1
Hi,
Good catch.
Too bad I missed it.
/Marcus
Quoted 5 lines · Dan Carpenter
This code uses
sizeof()instead ofARRAY_SIZE()so it reads beyond the end of the mcp3911_osr_table[] array.Fixes 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")Signed-off-by Dan Carpenter <[email protected]>
Reviewed-by Marcus Folkesson <[email protected]>
Quoted 20 lines
--- drivers/iio/adc/mcp3911.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/mcp3911.c +1
-1@@ -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,Signature · 1 line
2.35.1
Quoted 7 lines · On Mon, 26 Sep 2022 13:18:58 +0200 Marcus Folkesson…
Hi,
Good catch.
Too bad I missed it./Marcus
Quoted 8 lines
Quoted 5 lines · Dan Carpenter
This code uses
sizeof()instead ofARRAY_SIZE()so it reads beyond the end of the mcp3911_osr_table[] array.Fixes 6d965885f4ea ("iio: adc: mcp3911: add support for oversampling ratio")Signed-off-by Dan Carpenter <[email protected]>Reviewed-by Marcus Folkesson <[email protected]>
Applied to the fixes-togreg branch of iio.git, but I'm not going to push that tree out until Linus takes the char-misc-next pull request as otherwise I'll make a mess of linux-next as the trees will effectively merge out of normal order.
Jonathan
Quoted 21 lines
Quoted 21 lines
--- drivers/iio/adc/mcp3911.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/mcp3911.c +1
-1@@ -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,Signature · 1 line
2.35.1