linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Introduce dmam_zalloc_coherent()
@ 2017-08-08  9:15 Michael Moese
  2017-08-09 13:37 ` Christoph Hellwig
  2017-08-09 17:44 ` kbuild test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Moese @ 2017-08-08  9:15 UTC (permalink / raw)
  To: Christoph Hellwig, Marek Szyprowski, Robin Murphy
  Cc: linux-kernel, Michael Moese

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-10  6:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-08  9:15 [PATCH] Introduce dmam_zalloc_coherent() Michael Moese
2017-08-09 13:37 ` Christoph Hellwig
2017-08-10  6:58   ` Marek Szyprowski
2017-08-09 17:44 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).