* [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
@ 2023-01-13 13:33 Anastasia Belova
2023-01-13 14:03 ` Andy Shevchenko
2023-01-13 18:41 ` [lvc-project] " Alexey Khoroshilov
0 siblings, 2 replies; 6+ messages in thread
From: Anastasia Belova @ 2023-01-13 13:33 UTC (permalink / raw)
To: Tomasz Duszynski
Cc: Anastasia Belova, Jonathan Cameron, Lars-Peter Clausen,
Andy Shevchenko, linux-iio, linux-kernel, lvc-project
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;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
2023-01-13 13:33 [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command Anastasia Belova
@ 2023-01-13 14:03 ` Andy Shevchenko
2023-01-13 18:41 ` [lvc-project] " Alexey Khoroshilov
1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-01-13 14:03 UTC (permalink / raw)
To: Anastasia Belova
Cc: Tomasz Duszynski, Jonathan Cameron, Lars-Peter Clausen,
linux-iio, linux-kernel, lvc-project
On Fri, Jan 13, 2023 at 3:33 PM Anastasia Belova <abelova@astralinux.ru> wrote:
>
> Check rsp for NULL-pointer before dereferencing.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
NAK.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
2023-01-13 13:33 [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command Anastasia Belova
2023-01-13 14:03 ` Andy Shevchenko
@ 2023-01-13 18:41 ` Alexey Khoroshilov
2023-01-13 18:47 ` Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Alexey Khoroshilov @ 2023-01-13 18:41 UTC (permalink / raw)
To: Anastasia Belova, Tomasz Duszynski
Cc: Lars-Peter Clausen, lvc-project, linux-iio, linux-kernel,
Andy Shevchenko, Jonathan Cameron
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
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
2023-01-13 18:41 ` [lvc-project] " Alexey Khoroshilov
@ 2023-01-13 18:47 ` Andy Shevchenko
2023-01-13 19:27 ` Alexey Khoroshilov
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2023-01-13 18:47 UTC (permalink / raw)
To: Alexey Khoroshilov
Cc: Anastasia Belova, Tomasz Duszynski, Lars-Peter Clausen,
lvc-project, linux-iio, linux-kernel, Jonathan Cameron
On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> On 13.01.2023 16:33, Anastasia Belova wrote:
> It seems it is better to put the whole validation loop under if (rsp)
> check.
No. The entire patch is redundant.
The code that calls this function is under the control of the same
driver, so we know how to avoid shooting in our foot.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
2023-01-13 18:47 ` Andy Shevchenko
@ 2023-01-13 19:27 ` Alexey Khoroshilov
2023-01-13 21:00 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Alexey Khoroshilov @ 2023-01-13 19:27 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Anastasia Belova, Tomasz Duszynski, Lars-Peter Clausen,
lvc-project, linux-iio, linux-kernel, Jonathan Cameron
On 13.01.2023 21:47, Andy Shevchenko wrote:
> On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
> <khoroshilov@ispras.ru> wrote:
>> On 13.01.2023 16:33, Anastasia Belova wrote:
>
>> It seems it is better to put the whole validation loop under if (rsp)
>> check.
>
> No. The entire patch is redundant.
> The code that calls this function is under the control of the same
> driver, so we know how to avoid shooting in our foot.
I see, there is an assumption that response is NULL iff size is zero.
May be it could be documented, because naming of arguments does not make
such assumption obvious for fresh readers.
--
Thank you,
Alexey
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [lvc-project] [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command
2023-01-13 19:27 ` Alexey Khoroshilov
@ 2023-01-13 21:00 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2023-01-13 21:00 UTC (permalink / raw)
To: Alexey Khoroshilov
Cc: Anastasia Belova, Tomasz Duszynski, Lars-Peter Clausen,
lvc-project, linux-iio, linux-kernel, Jonathan Cameron
On Fri, Jan 13, 2023 at 9:27 PM Alexey Khoroshilov
<khoroshilov@ispras.ru> wrote:
> On 13.01.2023 21:47, Andy Shevchenko wrote:
> > On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
> > <khoroshilov@ispras.ru> wrote:
> >> On 13.01.2023 16:33, Anastasia Belova wrote:
> >
> >> It seems it is better to put the whole validation loop under if (rsp)
> >> check.
> >
> > No. The entire patch is redundant.
> > The code that calls this function is under the control of the same
> > driver, so we know how to avoid shooting in our foot.
>
> I see, there is an assumption that response is NULL iff size is zero.
Yes. ->read() is called with (NULL, 0) and the code copes with this.
A similar situation was discussed recently and Linus T. rejected a
proposed change in vsnprintf().
> May be it could be documented, because naming of arguments does not make
> such assumption obvious for fresh readers.
Documentation improvements are always appreciated!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-01-13 21:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13 13:33 [PATCH] iio: chemical: scd30: Add check for NULL in scd30_i2c_command Anastasia Belova
2023-01-13 14:03 ` Andy Shevchenko
2023-01-13 18:41 ` [lvc-project] " Alexey Khoroshilov
2023-01-13 18:47 ` Andy Shevchenko
2023-01-13 19:27 ` Alexey Khoroshilov
2023-01-13 21:00 ` Andy Shevchenko
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®