[PATCH] dma: add function to check a buffer for proper DMA alignment

Sascha Hauer s.hauer at pengutronix.de
Thu Mar 20 05:09:07 PDT 2025


Add dma_map_buf_is_aligned() which can be used to check if a buffer is
sufficiently aligned for DMA.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 include/dma.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/dma.h b/include/dma.h
index 5877f4b13c..41eeacc478 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -141,4 +141,9 @@ void dma_free_coherent(struct device *dev, void *mem, dma_addr_t dma_handle, siz
 void *dma_alloc_writecombine(struct device *dev, size_t size, dma_addr_t *dma_handle);
 #endif
 
+static inline bool dma_map_buf_is_aligned(struct device *dev, void *buf, size_t size)
+{
+	return IS_ALIGNED((uintptr_t)buf, ARCH_DMA_MINALIGN) &&
+		IS_ALIGNED(size, ARCH_DMA_MINALIGN);
+}
 #endif /* __DMA_H */
-- 
2.39.5




More information about the barebox mailing list