mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] dma: add function to check a buffer for proper DMA alignment
@ 2025-03-20 12:51 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2025-03-20 12:51 UTC (permalink / raw)
  To: Barebox List

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

Link: https://lore.kernel.org/r/20250320120907.204013-1-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

---

Changes since v2:
- make buf argument const
- use PTR_IS_ALIGNED for pointer checking
---
 include/dma.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/dma.h b/include/dma.h
index 5877f4b13c..cb44963cc0 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, const void *buf, size_t size)
+{
+	return PTR_IS_ALIGNED(buf, ARCH_DMA_MINALIGN) &&
+		IS_ALIGNED(size, ARCH_DMA_MINALIGN);
+}
 #endif /* __DMA_H */
-- 
2.39.5




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-03-20 12:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-20 12:51 [PATCH v2] dma: add function to check a buffer for proper DMA alignment Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox