[PATCH 6/6] iio: proximity: sx9360: reject negative hysteresis values

From: Arnav Kapoor

Date: Mon Nov 16 2026 - 15:55:35 EST


sx9360_write_hysteresis() copies the value into an unsigned int before
comparing it with the threshold, so a negative value becomes a large
one, passes the "val >= pthresh >> 2" check and sets the largest
hysteresis instead of being rejected. Return -EINVAL for negative
values.

Fixes: 1cdb4c47f7f5 ("iio:proximity:sx9360: Add sx9360 support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9360.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c
index 26190f9c6c1f..9989b0dbeae0 100644
--- a/drivers/iio/proximity/sx9360.c
+++ b/drivers/iio/proximity/sx9360.c
@@ -529,6 +529,9 @@ static int sx9360_write_hysteresis(struct sx_common_data *data, int _val)
unsigned int hyst, val = _val;
int ret, pthresh;

+ if (_val < 0)
+ return -EINVAL;
+
ret = sx9360_read_thresh(data, &pthresh);
if (ret < 0)
return ret;
--
2.53.0