[PATCH v2 01/15] iio: adc: ad4134: Sign extend sample data

From: Marcelo Schmitt

Date: Tue Sep 15 2026 - 15:16:25 EST


Sign extend ADC sample data for correct delivery of negative ADC input
difference.

Fixes: e0bc6d7e2584 ("iio: adc: Initial support for AD4134")
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
---
New patch in v2.

drivers/iio/adc/ad4134.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad4134.c b/drivers/iio/adc/ad4134.c
index 0490218bb0e9..7d40c0521bb3 100644
--- a/drivers/iio/adc/ad4134.c
+++ b/drivers/iio/adc/ad4134.c
@@ -172,6 +172,7 @@ static int ad4134_data_read(struct ad4134_state *st, unsigned int reg,
unsigned int *val)
{
unsigned int i;
+ u32 sample;
int ret;

/*
@@ -196,8 +197,9 @@ static int ad4134_data_read(struct ad4134_state *st, unsigned int reg,
* Clock out data from all channels to avoid that.
*/
if (i == AD4134_VREG_CH(reg))
- *val = get_unaligned_be24(st->rx_buf);
+ sample = get_unaligned_be24(st->rx_buf);
}
+ *val = sign_extend32(sample, AD4134_CHAN_PRECISION_BITS - 1);

return 0;
}
--
2.53.0