Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1706244

[PATCH] Introduce dmam_zalloc_coherent()

From Michael Moese <michael.moese@men.de>
Newsgroups linux.kernel
Subject [PATCH] Introduce dmam_zalloc_coherent()
Date 2017-08-08 11:20 +0200
Message-ID <uc8Q9-5YJ-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


All memory allocation functions have a pendant for allocating zeroed
memory, but dmam_alloc_coherent does not have such a pendant.
However, it is easier to read dmam_zalloc_coherent than passing an extra
flag or, even worse, see memset() after the allocation.
This patch adds an inline function dmam_zalloc_coherent(), exactly like
the implementation of dma_zalloc_coherent().

Signed-off-by: Michael Moese <michael.moese@men.de>
---
 include/linux/dma-mapping.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 03c0196a6f24..cf6cbda76ee2 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -761,6 +761,15 @@ extern void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
 extern void *dmam_alloc_attrs(struct device *dev, size_t size,
 			      dma_addr_t *dma_handle, gfp_t gfp,
 			      unsigned long attrs);
+
+static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
+					dma_addr_t *dma_handle, gfp_t flag)
+{
+	void *ret = dmam_alloc_coherent(dev, size, dma_handle,
+					flag | __GFP_ZERO);
+	return ret;
+}
+
 #ifdef CONFIG_HAVE_GENERIC_DMA_COHERENT
 extern int dmam_declare_coherent_memory(struct device *dev,
 					phys_addr_t phys_addr,
-- 
2.13.1

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH] Introduce dmam_zalloc_coherent() Michael Moese <michael.moese@men.de> - 2017-08-08 11:20 +0200
  Re: [PATCH] Introduce dmam_zalloc_coherent() Christoph Hellwig <hch@lst.de> - 2017-08-09 15:40 +0200
    Re: [PATCH] Introduce dmam_zalloc_coherent() Marek Szyprowski <m.szyprowski@samsung.com> - 2017-08-10 09:00 +0200
  Re: [PATCH] Introduce dmam_zalloc_coherent() kbuild test robot <lkp@intel.com> - 2017-08-09 19:50 +0200

csiph-web