Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command

From: Alexey Khoroshilov
Date: Fri Jan 13 2023 - 13:41:56 EST


On 13.01.2023 16:33, Anastasia Belova wrote:
> Check rsp for NULL-pointer before dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: e510190e0139 ("iio: chemical: scd30: add I2C interface driver")
> Signed-off-by: Anastasia Belova <abelova@xxxxxxxxxxxxx>
> ---
> drivers/iio/chemical/scd30_i2c.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/chemical/scd30_i2c.c b/drivers/iio/chemical/scd30_i2c.c
> index bae479a4721f..84baf67fc0ce 100644
> --- a/drivers/iio/chemical/scd30_i2c.c
> +++ b/drivers/iio/chemical/scd30_i2c.c
> @@ -101,8 +101,10 @@ static int scd30_i2c_command(struct scd30_state *state, enum scd30_cmd cmd, u16
> return -EIO;
> }
>
> - *rsp++ = buf[i];
> - *rsp++ = buf[i + 1];
> + if (rsp) {
> + *rsp++ = buf[i];
> + *rsp++ = buf[i + 1];
> + }
> }
>
> return 0;
>


It seems it is better to put the whole validation loop under if (rsp)
check.

--
Alexey