[PATCH master 03/23] dma: add definition for dma_zalloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For use by functions that want a zeroed buffer for DMA use, implement
dma_zalloc(). Having this in a single place instead of open-coding makes
it easier in future to possibly optimize zeroing of the buffer and makes
follow-up changes more concise.

Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 drivers/dma/map.c | 11 +++++++++++
 include/dma.h     |  6 ++++++
 2 files changed, 17 insertions(+)

diff --git a/drivers/dma/map.c b/drivers/dma/map.c
index ed7d3b68ffb1..e2656a27f183 100644
--- a/drivers/dma/map.c
+++ b/drivers/dma/map.c
@@ -7,6 +7,17 @@ void *dma_alloc(size_t size)
 	return xmemalign(DMA_ALIGNMENT, ALIGN(size, DMA_ALIGNMENT));
 }
 
+void *dma_zalloc(size_t size)
+{
+	void *buf;
+
+	buf = dma_alloc(size);
+	if (buf)
+		memset(buf, 0x00, size);
+
+	return buf;
+}
+
 void dma_sync_single_for_cpu(struct device *dev, dma_addr_t address,
 			     size_t size, enum dma_data_direction dir)
 {
diff --git a/include/dma.h b/include/dma.h
index 0b77949eaf05..a69072280bd5 100644
--- a/include/dma.h
+++ b/include/dma.h
@@ -23,11 +23,17 @@
 
 #ifdef CONFIG_HAS_DMA
 void *dma_alloc(size_t size);
+void *dma_zalloc(size_t size);
 #else
 static inline void *dma_alloc(size_t size)
 {
 	return malloc(size);
 }
+
+static inline void *dma_zalloc(size_t size)
+{
+	return calloc(size, 1);
+}
 #endif
 
 static inline void dma_free(void *mem)
-- 
2.39.2





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux