[PATCH 2/3] iio: proximity: sx9324: reject fractional event values

From: Arnav Kapoor

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


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

diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 762c327063f9..b97fe1abde53 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -712,6 +712,10 @@ static int sx9324_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 sx9324_write_thresh(data, chan, val);
--
2.53.0