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

From: Arnav Kapoor

Date: Tue Nov 17 2026 - 14:16:09 EST


On Tue, Nov 17, 2026 at 09:09:42PM +0200, Andy Shevchenko wrote:
> As noticed earlier not all cases might have this issue, please elaborate if
> this is for 32- and 64-bit cases or only for the former.

Both. val is an unsigned int and pthresh an int, so in
"val >= pthresh >> 2" the right side is converted to unsigned int and
the comparison is done in 32 bits; long doesn't come into it. A
negative _val such as -1 becomes 0xffffffff, which is >= any threshold,
so it sets the largest hysteresis on 32-bit and 64-bit alike. I'll
spell that out in the v2 commit message.

> > unsigned int hyst, val = _val;
> > int ret, pthresh;
> >
> > + if (_val < 0)
> > + return -EINVAL;
>
> Same (semantic) issue, you are checking variable after its use.

Agreed. In v2 the check comes first and val is assigned after it, here
and in 6/6. Your comments on 5/6 will get the same changes as 2/6.

Thanks,
Arnav