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

From: Arnav Kapoor

Date: Mon Nov 16 2026 - 15:54:24 EST


sx9324_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: 4c18a890dff8 ("iio:proximity:sx9324: Add SX9324 support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9324.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 39760c92552b..9b7ac1d56e53 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -638,6 +638,9 @@ static int sx9324_write_hysteresis(struct sx_common_data *data,
unsigned int hyst, val = _val;
int ret, pthresh;

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