Skip to content

Commit fa19c30

Browse files
dlechjic23
authored andcommitted
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á <nuno.sa@analog.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250507-iio-introduce-iio_declare_buffer_with_ts-v6-1-4aee1b9f1b89@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 666eae6 commit fa19c30

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

include/linux/iio/iio.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/device.h>
1111
#include <linux/cdev.h>
1212
#include <linux/compiler_types.h>
13+
#include <linux/minmax.h>
1314
#include <linux/slab.h>
1415
#include <linux/iio/types.h>
1516
/* IIO TODO LIST */
@@ -775,8 +776,14 @@ static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev)
775776
* to in turn include IIO_DMA_MINALIGN'd elements such as buffers which
776777
* must not share cachelines with the rest of the structure, thus making
777778
* them safe for use with non-coherent DMA.
779+
*
780+
* A number of drivers also use this on buffers that include a 64-bit timestamp
781+
* that is used with iio_push_to_buffer_with_ts(). Therefore, in the case where
782+
* DMA alignment is not sufficient for proper timestamp alignment, we align to
783+
* 8 bytes instead.
778784
*/
779-
#define IIO_DMA_MINALIGN ARCH_DMA_MINALIGN
785+
#define IIO_DMA_MINALIGN MAX(ARCH_DMA_MINALIGN, sizeof(s64))
786+
780787
struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv);
781788

782789
/* The information at the returned address is guaranteed to be cacheline aligned */

0 commit comments

Comments
 (0)