2023-01-13 19:03:06

by Andy Shevchenko

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

On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
<[email protected]> 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


2023-01-13 19:29:40

by Alexey Khoroshilov

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

On 13.01.2023 21:47, Andy Shevchenko wrote:
> On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
> <[email protected]> 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

2023-01-13 21:10:22

by Andy Shevchenko

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

On Fri, Jan 13, 2023 at 9:27 PM Alexey Khoroshilov
<[email protected]> wrote:
> On 13.01.2023 21:47, Andy Shevchenko wrote:
> > On Fri, Jan 13, 2023 at 8:41 PM Alexey Khoroshilov
> > <[email protected]> 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