From: Jonathan Cameron <jic23@kernel.org>
To: Karan Sanghavi <karansanghvi98@gmail.com>
Cc: Tomasz Duszynski <tduszyns@gmail.com>,
Lars-Peter Clausen <lars@metafoo.de>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>,
Karan Sanghavi <karansanghavi98@gmail.com>
Subject: Re: [PATCH] iio: chemical: sps30: Add Null pointer check
Date: Sat, 19 Oct 2024 12:21:33 +0100 [thread overview]
Message-ID: <20241019122133.13d59dfb@jic23-huawei> (raw)
In-Reply-To: <20241018-cid1593398badshift-v1-1-11550a10ff25@gmail.com>
On Fri, 18 Oct 2024 18:54:42 +0000
Karan Sanghavi <karansanghvi98@gmail.com> wrote:
> Add a Null pointer check before assigning and incrementing
> the null pointer
>
> Signed-off-by: Karan Sanghavi <karansanghvi98@gmail.com>
It would be a bug if rsp_size was anything other than 0 and rsp is NULL.
So this looks like a false positive as the loop will never be
entered.
How did you find it, in particular have you managed to trigger this
in the driver?
Jonathan
> ---
> drivers/iio/chemical/sps30_i2c.c | 20 +++++++++++---------
> 1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/chemical/sps30_i2c.c b/drivers/iio/chemical/sps30_i2c.c
> index 1b21b6bcd0e7..d2142e4c748c 100644
> --- a/drivers/iio/chemical/sps30_i2c.c
> +++ b/drivers/iio/chemical/sps30_i2c.c
> @@ -105,16 +105,18 @@ static int sps30_i2c_command(struct sps30_state *state, u16 cmd, void *arg, size
> return ret;
>
> /* validate received data and strip off crc bytes */
> - tmp = rsp;
> - for (i = 0; i < rsp_size; i += 3) {
> - crc = crc8(sps30_i2c_crc8_table, buf + i, 2, CRC8_INIT_VALUE);
> - if (crc != buf[i + 2]) {
> - dev_err(state->dev, "data integrity check failed\n");
> - return -EIO;
> + if (rsp) {
> + tmp = rsp;
> + for (i = 0; i < rsp_size; i += 3) {
> + crc = crc8(sps30_i2c_crc8_table, buf + i, 2, CRC8_INIT_VALUE);
> + if (crc != buf[i + 2]) {
> + dev_err(state->dev, "data integrity check failed\n");
> + return -EIO;
> + }
> +
> + *tmp++ = buf[i];
> + *tmp++ = buf[i + 1];
> }
> -
> - *tmp++ = buf[i];
> - *tmp++ = buf[i + 1];
> }
>
> return 0;
>
> ---
> base-commit: f2493655d2d3d5c6958ed996b043c821c23ae8d3
> change-id: 20241018-cid1593398badshift-9c512a3b92d9
>
> Best regards,
next prev parent reply other threads:[~2024-10-19 11:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 18:54 [PATCH] iio: chemical: sps30: Add Null pointer check Karan Sanghavi
2024-10-19 11:21 ` Jonathan Cameron [this message]
2024-10-19 12:08 ` Karan Sanghavi
2024-10-21 19:56 ` Shuah Khan
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=20241019122133.13d59dfb@jic23-huawei \
--to=jic23@kernel.org \
--cc=karansanghavi98@gmail.com \
--cc=karansanghvi98@gmail.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tduszyns@gmail.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