mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexey Khoroshilov <khoroshilov@ispras.ru>
To: Anastasia Belova <abelova@astralinux.ru>,
	Tomasz Duszynski <tomasz.duszynski@octakon.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	lvc-project@linuxtesting.org, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
Date: Fri, 13 Jan 2023 21:41:40 +0300	[thread overview]
Message-ID: <c0c7d2d7-648d-feb3-14ea-c2ab3baddfb1@ispras.ru> (raw)
In-Reply-To: <20230113133320.7531-1-abelova@astralinux.ru>

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@astralinux.ru>
> ---
>  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

  parent reply	other threads:[~2023-01-13 18:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 13:33 Anastasia Belova
2023-01-13 14:03 ` Andy Shevchenko
2023-01-13 18:41 ` Alexey Khoroshilov [this message]
2023-01-13 18:47   ` [lvc-project] " Andy Shevchenko
2023-01-13 19:27     ` Alexey Khoroshilov
2023-01-13 21:00       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0c7d2d7-648d-feb3-14ea-c2ab3baddfb1@ispras.ru \
    --to=khoroshilov@ispras.ru \
    --cc=abelova@astralinux.ru \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=tomasz.duszynski@octakon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®