From: David Lechner Date: Wed, 7 May 2025 20:42:40 +0000 (-0500) Subject: iio: make IIO_DMA_MINALIGN minimum of 8 bytes X-Git-Tag: v6.16-rc1~30^2~4^2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fa19c303254bae5b8d105ecdc7d714d092f2adda;p=thirdparty%2Fkernel%2Fstable.git iio: make IIO_DMA_MINALIGN minimum of 8 bytes Add a condition to ensure that IIO_DMA_MINALIGN is at least 8 bytes. On some 32-bit architectures, IIO_DMA_MINALIGN is 4. In many cases, drivers are using this alignment for buffers that include a 64-bit timestamp that is used with iio_push_to_buffers_with_ts(), which expects the timestamp to be aligned to 8 bytes. To handle this, we can just make IIO_DMA_MINALIGN at least 8 bytes. Reviewed-by: Nuno Sá Signed-off-by: David Lechner Link: https://patch.msgid.link/20250507-iio-introduce-iio_declare_buffer_with_ts-v6-1-4aee1b9f1b89@baylibre.com Signed-off-by: Jonathan Cameron --- diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 638cf2420fbd8..a574f22398e45 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include /* IIO TODO LIST */ @@ -775,8 +776,14 @@ static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev) * to in turn include IIO_DMA_MINALIGN'd elements such as buffers which * must not share cachelines with the rest of the structure, thus making * them safe for use with non-coherent DMA. + * + * A number of drivers also use this on buffers that include a 64-bit timestamp + * that is used with iio_push_to_buffer_with_ts(). Therefore, in the case where + * DMA alignment is not sufficient for proper timestamp alignment, we align to + * 8 bytes instead. */ -#define IIO_DMA_MINALIGN ARCH_DMA_MINALIGN +#define IIO_DMA_MINALIGN MAX(ARCH_DMA_MINALIGN, sizeof(s64)) + struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); /* The information at the returned address is guaranteed to be cacheline aligned */