Commit 3d0fc341 authored by Christoph Hellwig's avatar Christoph Hellwig

dma-direct: consolidate the error handling in dma_direct_alloc_pages

Use a goto label to merge two error return cases.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarRobin Murphy <robin.murphy@arm.com>
parent 4f8232bb
...@@ -169,11 +169,8 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, ...@@ -169,11 +169,8 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
ret = dma_common_contiguous_remap(page, PAGE_ALIGN(size), ret = dma_common_contiguous_remap(page, PAGE_ALIGN(size),
dma_pgprot(dev, PAGE_KERNEL, attrs), dma_pgprot(dev, PAGE_KERNEL, attrs),
__builtin_return_address(0)); __builtin_return_address(0));
if (!ret) { if (!ret)
dma_free_contiguous(dev, page, size); goto out_free_pages;
return ret;
}
memset(ret, 0, size); memset(ret, 0, size);
goto done; goto done;
} }
...@@ -186,8 +183,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, ...@@ -186,8 +183,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
* so log an error and fail. * so log an error and fail.
*/ */
dev_info(dev, "Rejecting highmem page from CMA.\n"); dev_info(dev, "Rejecting highmem page from CMA.\n");
dma_free_contiguous(dev, page, size); goto out_free_pages;
return NULL;
} }
ret = page_address(page); ret = page_address(page);
...@@ -207,6 +203,9 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size, ...@@ -207,6 +203,9 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
else else
*dma_handle = phys_to_dma(dev, page_to_phys(page)); *dma_handle = phys_to_dma(dev, page_to_phys(page));
return ret; return ret;
out_free_pages:
dma_free_contiguous(dev, page, size);
return NULL;
} }
void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr, void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment