Skip to content

Commit

Permalink
arm64: Honor __GFP_ZERO in dma allocations
Browse files Browse the repository at this point in the history
Current implementation doesn't zero out the pages allocated.
Honor the __GFP_ZERO flag and zero out if set.

Cc: <[email protected]> # v3.14+
Acked-by: Will Deacon <[email protected]>
Signed-off-by: Suzuki K. Poulose <[email protected]>
Signed-off-by: Catalin Marinas <[email protected]>
  • Loading branch information
Suzuki K. Poulose authored and ctmarinas committed Mar 20, 2015
1 parent 130c93f commit 7132813
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions arch/arm64/mm/dma-mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static int __init early_coherent_pool(char *p)
}
early_param("coherent_pool", early_coherent_pool);

static void *__alloc_from_pool(size_t size, struct page **ret_page)
static void *__alloc_from_pool(size_t size, struct page **ret_page, gfp_t flags)
{
unsigned long val;
void *ptr = NULL;
Expand All @@ -67,6 +67,8 @@ static void *__alloc_from_pool(size_t size, struct page **ret_page)

*ret_page = phys_to_page(phys);
ptr = (void *)val;
if (flags & __GFP_ZERO)
memset(ptr, 0, size);
}

return ptr;
Expand Down Expand Up @@ -101,6 +103,7 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
flags |= GFP_DMA;
if (IS_ENABLED(CONFIG_DMA_CMA) && (flags & __GFP_WAIT)) {
struct page *page;
void *addr;

size = PAGE_ALIGN(size);
page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
Expand All @@ -109,7 +112,10 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
return NULL;

*dma_handle = phys_to_dma(dev, page_to_phys(page));
return page_address(page);
addr = page_address(page);
if (flags & __GFP_ZERO)
memset(addr, 0, size);
return addr;
} else {
return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
}
Expand Down Expand Up @@ -146,7 +152,7 @@ static void *__dma_alloc(struct device *dev, size_t size,

if (!coherent && !(flags & __GFP_WAIT)) {
struct page *page = NULL;
void *addr = __alloc_from_pool(size, &page);
void *addr = __alloc_from_pool(size, &page, flags);

if (addr)
*dma_handle = phys_to_dma(dev, page_to_phys(page));
Expand Down

0 comments on commit 7132813

Please sign in to comment.