[PATCH 3/3] iio: proximity: sx9360: reject fractional event values
From: Arnav Kapoor
Date: Fri Dec 04 2026 - 11:32:30 EST
sx9360_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: 1cdb4c47f7f5 ("iio:proximity:sx9360: Add sx9360 support")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/sx9360.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/iio/proximity/sx9360.c b/drivers/iio/proximity/sx9360.c
index b50bdc293934..1fcf270ce5cf 100644
--- a/drivers/iio/proximity/sx9360.c
+++ b/drivers/iio/proximity/sx9360.c
@@ -599,6 +599,10 @@ static int sx9360_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 sx9360_write_thresh(data, val);
--
2.53.0