[PATCH 2/5] iio: dac: ad5758: Reject out-of-range raw values
From: Arka Mondal
Date: Fri Sep 18 2026 - 08:26:24 EST
ad5758_write_raw() passes the value from userspace straight to
ad5758_spi_reg_write(), which keeps only the low 16 bits. Writing -1
to the raw attribute gives full-scale output, and 65536 gives code 0.
Return -EINVAL for values outside 0 to U16_MAX, as ad5755 does.
Fixes: 28d1a7ac2a0d ("iio: dac: Add AD5758 support")
Signed-off-by: Arka Mondal <arka@xxxxxxxxxxxxxx>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/dac/ad5758.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index ba381bd252d1..2a9e907b5eb8 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -556,6 +556,9 @@ static int ad5758_write_raw(struct iio_dev *indio_dev,
switch (info) {
case IIO_CHAN_INFO_RAW:
+ if (val < 0 || val > U16_MAX)
+ return -EINVAL;
+
mutex_lock(&st->lock);
ret = ad5758_spi_reg_write(st, AD5758_DAC_INPUT, val);
mutex_unlock(&st->lock);
--
2.55.0