Re: [PATCH] iio: adc: mcp3911: fix sizeof() vs ARRAY_SIZE() bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Good catch.
Too bad I missed it.

/Marcus

On Mon, Sep 26, 2022 at 12:10:37PM +0300, Dan Carpenter wrote:
> 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 <dan.carpenter@xxxxxxxxxx>

Reviewed-by: Marcus Folkesson <marcus.folkesson@xxxxxxxxx>

> ---
>  drivers/iio/adc/mcp3911.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/mcp3911.c b/drivers/iio/adc/mcp3911.c
> index b35fd2c9c3c0..015a9ffdb26a 100644
> --- a/drivers/iio/adc/mcp3911.c
> +++ b/drivers/iio/adc/mcp3911.c
> @@ -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,
> -- 
> 2.35.1
> 

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux