[PATCH v6 02/16] iio: adc: xilinx-xadc: Refine Zynq read/write error handling on timeout/interrupt

From: Dileep Kumar Nagavarapu

Date: Wed Nov 25 2026 - 12:12:10 EST


Refine the error codes returned from the wait, the same way in both
xadc_zynq_write_adc_reg() and xadc_zynq_read_adc_reg(): a timeout
(ret == 0) now returns -ETIMEDOUT instead of the previous -EIO,
giving a more precise errno for this condition. An interrupted wait
(ret < 0) now propagates that error to the caller instead of being
silently treated as success.

xadc_zynq_write_adc_reg() waits on xadc->completion after issuing the
Zynq DRP write command, then drains the response word from
XADC_ZYNQ_REG_DFIFO. The DFIFO read already ran unconditionally after
the wait, regardless of outcome.

Fixes: bdc8cda1d010 ("iio:adc: Add Xilinx XADC driver")
Co-developed-by: Sai Krishna Potthuri <sai.krishna.potthuri@xxxxxxx>
Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@xxxxxxx>
Signed-off-by: Dileep Kumar Nagavarapu <dileepkumar.nagavarapu@xxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/iio/adc/xilinx-xadc-core.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
index 222571e75cb3..55cb75d4239b 100644
--- a/drivers/iio/adc/xilinx-xadc-core.c
+++ b/drivers/iio/adc/xilinx-xadc-core.c
@@ -196,14 +196,16 @@ static int xadc_zynq_write_adc_reg(struct xadc *xadc, unsigned int reg,
spin_unlock_irq(&xadc->lock);

ret = wait_for_completion_interruptible_timeout(&xadc->completion, HZ);
- if (ret == 0)
- ret = -EIO;
- else
- ret = 0;

xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &tmp);

- return ret;
+ if (ret < 0)
+ return ret;
+
+ if (ret == 0)
+ return -ETIMEDOUT;
+
+ return 0;
}

static int xadc_zynq_read_adc_reg(struct xadc *xadc, unsigned int reg,
@@ -231,11 +233,12 @@ static int xadc_zynq_read_adc_reg(struct xadc *xadc, unsigned int reg,
xadc_zynq_update_intmsk(xadc, XADC_ZYNQ_INT_DFIFO_GTH, 0);
spin_unlock_irq(&xadc->lock);
ret = wait_for_completion_interruptible_timeout(&xadc->completion, HZ);
- if (ret == 0)
- ret = -EIO;
if (ret < 0)
return ret;

+ if (ret == 0)
+ return -ETIMEDOUT;
+
xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &resp);
xadc_read_reg(xadc, XADC_ZYNQ_REG_DFIFO, &resp);

--
2.34.1