diff options
author | Christoph Hellwig <hch@lst.de> | 2019-06-03 10:14:31 +0300 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2019-09-04 12:13:20 +0300 |
commit | 5cf4537975bbd5691b9ddd015d540bb92f61e322 (patch) | |
tree | f77c8831902447d5c079eb8d36d4819d426d6e06 /kernel/dma | |
parent | 512317401f6a337e617ec284d20dec5fa3a951ec (diff) | |
download | linux-5cf4537975bbd5691b9ddd015d540bb92f61e322.tar.xz |
dma-mapping: introduce a dma_common_find_pages helper
A helper to find the backing page array based on a virtual address.
This also ensures we do the same vm_flags check everywhere instead
of slightly different or missing ones in a few places.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma')
-rw-r--r-- | kernel/dma/remap.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/kernel/dma/remap.c b/kernel/dma/remap.c index f6b90521a7e4..ca4e5d44b571 100644 --- a/kernel/dma/remap.c +++ b/kernel/dma/remap.c @@ -11,6 +11,15 @@ #include <linux/slab.h> #include <linux/vmalloc.h> +struct page **dma_common_find_pages(void *cpu_addr) +{ + struct vm_struct *area = find_vm_area(cpu_addr); + + if (!area || area->flags != VM_DMA_COHERENT) + return NULL; + return area->pages; +} + static struct vm_struct *__dma_common_pages_remap(struct page **pages, size_t size, pgprot_t prot, const void *caller) { @@ -78,9 +87,9 @@ void *dma_common_contiguous_remap(struct page *page, size_t size, */ void dma_common_free_remap(void *cpu_addr, size_t size) { - struct vm_struct *area = find_vm_area(cpu_addr); + struct page **pages = dma_common_find_pages(cpu_addr); - if (!area || area->flags != VM_DMA_COHERENT) { + if (!pages) { WARN(1, "trying to free invalid coherent area: %p\n", cpu_addr); return; } |