Re: [PATCH v2 3/6] iio: proximity: sx9324: reject negative hysteresis values

From: Jonathan Cameron

Date: Sat Nov 28 2026 - 18:46:08 EST


On Mon, 23 Nov 2026 13:18:01 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxx> wrote:

> On Mon, Nov 23, 2026 at 01:15:42PM +0200, Andy Shevchenko wrote:
> > On Sun, Nov 22, 2026 at 01:16:43PM +0530, Arnav Kapoor wrote:
>
> ...
>
> > > static int sx9324_write_hysteresis(struct sx_common_data *data,
> > > const struct iio_chan_spec *chan, int _val)
> > > {
> > > - unsigned int hyst, val = _val;
> > > + unsigned int hyst, val;
> > > int ret, pthresh;
> > >
> > > + if (_val < 0)
> > > + return -EINVAL;
> > > +
> > > + val = _val;
> >
> > You can validate assigned value instead as there are no side-effects.
> > But while I wrote it, I have noticed that there is actually one, we
> > modify the sign of the value. With that in mind maybe better to have
> >
> > /*
> > * Assume only positive input, negative, after conversion to unsigned
> > * is unsupported. // or something like this
> > */
> > val = _val;
> > if (val > INT_MAX)
> > return -EINVAL;
>
> On the second thought, the original < 0 check might be cleaner... Dunno.
> Jonathan, what do you think?
I think the < 0 is indeed cleaner. Hopefully that is what is in v3!

This series lost under my usual approach of working backwards through
my inbox whenever I get time to do IIO review! Sorry for delay.
>