Re: [PATCH v2 3/6] iio: proximity: sx9324: reject negative hysteresis values
From: Andy Shevchenko
Date: Mon Nov 23 2026 - 06:18:09 EST
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?
--
With Best Regards,
Andy Shevchenko