aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Chen <miles.chen@mediatek.com>2018-02-22 06:22:20 -0500
committerChristoph Hellwig <hch@lst.de>2018-02-22 18:02:33 -0500
commitaf1da686843750809738c01e153320106e890804 (patch)
treeed3a996f8f9dce16a0ba24b015a1e16bea5920c1
parenta638af00b27266c09ab7ac69141e6f4ac6c00eff (diff)
dma-debug: fix memory leak in debug_dma_alloc_coherent
Marty reported a memory leakage introduced by commit 3aaabbf1c39e ("lib/dma-debug.c: fix incorrect pfn calculation"). Fix it by checking the virtual address before allocating the entry. This patch also use virt_addr_valid() instead of virt_to_page() to check if a virtual address is linear. Fixes: 3aaabbf1 ("lib/dma-debug.c: fix incorrect pfn calculation") Reported-by: Marty Faltesek <mfaltesek@google.com> Signed-off-by: Miles Chen <miles.chen@mediatek.com> Acked-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--lib/dma-debug.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/dma-debug.c b/lib/dma-debug.c
index 1b34d210452c..7f5cdc1e6b29 100644
--- a/lib/dma-debug.c
+++ b/lib/dma-debug.c
@@ -1491,12 +1491,12 @@ void debug_dma_alloc_coherent(struct device *dev, size_t size,
1491 if (unlikely(virt == NULL)) 1491 if (unlikely(virt == NULL))
1492 return; 1492 return;
1493 1493
1494 entry = dma_entry_alloc(); 1494 /* handle vmalloc and linear addresses */
1495 if (!entry) 1495 if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
1496 return; 1496 return;
1497 1497
1498 /* handle vmalloc and linear addresses */ 1498 entry = dma_entry_alloc();
1499 if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) 1499 if (!entry)
1500 return; 1500 return;
1501 1501
1502 entry->type = dma_debug_coherent; 1502 entry->type = dma_debug_coherent;
@@ -1528,7 +1528,7 @@ void debug_dma_free_coherent(struct device *dev, size_t size,
1528 }; 1528 };
1529 1529
1530 /* handle vmalloc and linear addresses */ 1530 /* handle vmalloc and linear addresses */
1531 if (!is_vmalloc_addr(virt) && !virt_to_page(virt)) 1531 if (!is_vmalloc_addr(virt) && !virt_addr_valid(virt))
1532 return; 1532 return;
1533 1533
1534 if (is_vmalloc_addr(virt)) 1534 if (is_vmalloc_addr(virt))