summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2019-06-03 09:14:31 +0200
committerChristoph Hellwig <hch@lst.de>2019-09-04 11:13:20 +0200
commit5cf4537975bbd5691b9ddd015d540bb92f61e322 (patch)
treef77c8831902447d5c079eb8d36d4819d426d6e06 /kernel
parent512317401f6a337e617ec284d20dec5fa3a951ec (diff)
downloadlinux-5cf4537975bbd5691b9ddd015d540bb92f61e322.tar.bz2
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')
-rw-r--r--kernel/dma/remap.c13
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;
}