Skip to content
Browse files

include/linux/dma-mapping.h: add dma_zalloc_coherent()

Lots of driver code does a dma_alloc_coherent() and then zeroes out the
memory with a memset.  Make it easy for them.

Cc: Alexandre Bounine <>
Signed-off-by: Andrew Morton <>
Signed-off-by: Linus Torvalds <>
  • Loading branch information...
1 parent c736de6 commit 842fa69f3e0c9a178b294e7af7c07f4c9d9e7af2 Andrew Morton committed with torvalds Nov 2, 2011
Showing with 17 additions and 0 deletions.
  1. +7 −0 Documentation/DMA-API.txt
  2. +10 −0 include/linux/dma-mapping.h
7 Documentation/DMA-API.txt
@@ -50,6 +50,13 @@ specify the GFP_ flags (see kmalloc) for the allocation (the
implementation may choose to ignore flags that affect the location of
the returned memory, like GFP_DMA).
+void *
+dma_zalloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t flag)
+Wraps dma_alloc_coherent() and also zeroes the returned memory if the
+allocation attempt succeeded.
dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
dma_addr_t dma_handle)
10 include/linux/dma-mapping.h
@@ -1,6 +1,7 @@
+#include <linux/string.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/dma-attrs.h>
@@ -117,6 +118,15 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask)
return -EIO;
+static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
+ dma_addr_t *dma_handle, gfp_t flag)
+ void *ret = dma_alloc_coherent(dev, size, dma_handle, flag);
+ if (ret)
+ memset(ret, 0, size);
+ return ret;
static inline int dma_get_cache_alignment(void)

0 comments on commit 842fa69

Please sign in to comment.
Something went wrong with that request. Please try again.