[PATCH] iio: adc: ti-ads7950: use iio_push_to_buffers_with_ts_unaligned()
From: David Lechner
Date: Sat Mar 07 2026 - 16:16:18 EST
Use iio_push_to_buffers_with_ts_unaligned() to avoid unaligned access
when writing the timestamp in the rx_buf.
The previous implementation would have been fine on architectures that
support 4-byte alignment of 64-bit integers but could cause issues on
architectures that require 8-byte alignment.
Fixes: 902c4b2446d4 ("iio: adc: New driver for TI ADS7950 chips")
Signed-off-by: David Lechner <dlechner@xxxxxxxxxxxx>
---
Since we were looking at this driver, I was going to convert this to use
IIO_DECLARE_DMA_BUFFER_WITH_TS() but then I noticed that we actually
have an unaligned access problem with the timestamp since we are
ignoring the first two elements in the rx_buf when pushing the data to
the buffer.
Unfortunately, this will cause a merge conflict with the series Dmitry
is working on. I don't think there is any rush to get this backported
since no one has reported a crash from unaligned access. Since fixes
should go before improvements, we could apply this to iio/togreg then
Dmitry can rebase his series on top of it.
---
drivers/iio/adc/ti-ads7950.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
index bbe1ce577789..53825c8b350a 100644
--- a/drivers/iio/adc/ti-ads7950.c
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -47,8 +47,6 @@
#define TI_ADS7950_MAX_CHAN 16
#define TI_ADS7950_NUM_GPIOS 4
-#define TI_ADS7950_TIMESTAMP_SIZE (sizeof(int64_t) / sizeof(__be16))
-
/* val = value, dec = left shift, bits = number of bits of the mask */
#define TI_ADS7950_EXTRACT(val, dec, bits) \
(((val) >> (dec)) & ((1 << (bits)) - 1))
@@ -105,8 +103,7 @@ struct ti_ads7950_state {
* DMA (thus cache coherency maintenance) may require the
* transfer buffers to live in their own cache lines.
*/
- u16 rx_buf[TI_ADS7950_MAX_CHAN + 2 + TI_ADS7950_TIMESTAMP_SIZE]
- __aligned(IIO_DMA_MINALIGN);
+ u16 rx_buf[TI_ADS7950_MAX_CHAN + 2] __aligned(IIO_DMA_MINALIGN);
u16 tx_buf[TI_ADS7950_MAX_CHAN + 2];
u16 single_tx;
u16 single_rx;
@@ -313,8 +310,9 @@ static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p)
if (ret < 0)
goto out;
- iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2],
- iio_get_time_ns(indio_dev));
+ iio_push_to_buffers_with_ts_unaligned(indio_dev, &st->rx_buf[2],
+ sizeof(u16) * TI_ADS7950_MAX_CHAN,
+ iio_get_time_ns(indio_dev));
out:
mutex_unlock(&st->slock);
---
base-commit: 6f25a6105c41a7d6b12986dbe80ded396a5667f8
change-id: 20260307-iio-adc-ti-ads7950-declare-dma-buffer-9d5269ffa8bb
Best regards,
--
David Lechner <dlechner@xxxxxxxxxxxx>