[PATCH 1/3] iio: proximity: sx9310: reject fractional event values

From: Arnav Kapoor

Date: Fri Dec 04 2026 - 11:32:22 EST


sx9310_write_event_val() ignores val2. The threshold, period and hysteresis
are all integers and are read back as IIO_VAL_INT, but the core parses
writes as IIO_VAL_INT_PLUS_MICRO, so a write like 1.5 is silently stored
as 1 and -0.999999 is taken as 0.

Return -EINVAL when val2 is not zero.

Suggested-by: Jonathan Cameron <jic23@xxxxxxxxxx>
Fixes: ad2b473e2ba3 ("iio: sx9310: Support setting proximity thresholds")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9310.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 0f7e46ec40a5..57a764075eb6 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -621,6 +621,10 @@ static int sx9310_write_event_val(struct iio_dev *indio_dev,
if (chan->type != IIO_PROXIMITY)
return -EINVAL;

+ /* All event values are integers */
+ if (val2)
+ return -EINVAL;
+
switch (info) {
case IIO_EV_INFO_VALUE:
return sx9310_write_thresh(data, chan, val);
--
2.53.0