Skip to content

Commit da83a72

Browse files
frno7Christoph Hellwig
authored andcommitted
lib/genalloc: add gen_pool_dma_zalloc() for zeroed DMA allocations
gen_pool_dma_zalloc() is a zeroed memory variant of gen_pool_dma_alloc(). Also document the return values of both, and indicate NULL as a "%NULL" constant. Signed-off-by: Fredrik Noring <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent dd3dced commit da83a72

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

include/linux/genalloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t,
121121
genpool_algo_t algo, void *data);
122122
extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size,
123123
dma_addr_t *dma);
124+
void *gen_pool_dma_zalloc(struct gen_pool *pool, size_t size, dma_addr_t *dma);
124125
extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
125126
extern void gen_pool_for_each_chunk(struct gen_pool *,
126127
void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);

lib/genalloc.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,14 @@ EXPORT_SYMBOL(gen_pool_alloc_algo);
337337
* gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
338338
* @pool: pool to allocate from
339339
* @size: number of bytes to allocate from the pool
340-
* @dma: dma-view physical address return value. Use NULL if unneeded.
340+
* @dma: dma-view physical address return value. Use %NULL if unneeded.
341341
*
342342
* Allocate the requested number of bytes from the specified pool.
343343
* Uses the pool allocation function (with first-fit algorithm by default).
344344
* Can not be used in NMI handler on architectures without
345345
* NMI-safe cmpxchg implementation.
346+
*
347+
* Return: virtual address of the allocated memory, or %NULL on failure
346348
*/
347349
void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
348350
{
@@ -362,6 +364,31 @@ void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
362364
}
363365
EXPORT_SYMBOL(gen_pool_dma_alloc);
364366

367+
/**
368+
* gen_pool_dma_zalloc - allocate special zeroed memory from the pool for
369+
* DMA usage
370+
* @pool: pool to allocate from
371+
* @size: number of bytes to allocate from the pool
372+
* @dma: dma-view physical address return value. Use %NULL if unneeded.
373+
*
374+
* Allocate the requested number of zeroed bytes from the specified pool.
375+
* Uses the pool allocation function (with first-fit algorithm by default).
376+
* Can not be used in NMI handler on architectures without
377+
* NMI-safe cmpxchg implementation.
378+
*
379+
* Return: virtual address of the allocated zeroed memory, or %NULL on failure
380+
*/
381+
void *gen_pool_dma_zalloc(struct gen_pool *pool, size_t size, dma_addr_t *dma)
382+
{
383+
void *vaddr = gen_pool_dma_alloc(pool, size, dma);
384+
385+
if (vaddr)
386+
memset(vaddr, 0, size);
387+
388+
return vaddr;
389+
}
390+
EXPORT_SYMBOL(gen_pool_dma_zalloc);
391+
365392
/**
366393
* gen_pool_free - free allocated special memory back to the pool
367394
* @pool: pool to free to

0 commit comments

Comments
 (0)