Messages in this thread Patch in this message | | | From | Michael Moese <> | Subject | [PATCH] Introduce dmam_zalloc_coherent() | Date | Tue, 8 Aug 2017 11:15:35 +0200 |
| |
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
| |