[PATCH 2/3] dma-buf: heaps: Add a WARN_ON should the vmap_cnt go negative

John Stultz john.stultz at linaro.org
Thu Jan 7 21:15:24 UTC 2021


We shouldn't vunmap more then we vmap, but if we do, make
sure we complain loudly.

Cc: Sumit Semwal <sumit.semwal at linaro.org>
Cc: Liam Mark <lmark at codeaurora.org>
Cc: Laura Abbott <labbott at kernel.org>
Cc: Brian Starkey <Brian.Starkey at arm.com>
Cc: Hridya Valsaraju <hridya at google.com>
Cc: Suren Baghdasaryan <surenb at google.com>
Cc: Sandeep Patil <sspatil at google.com>
Cc: Daniel Mentz <danielmentz at google.com>
Cc: Chris Goldsworthy <cgoldswo at codeaurora.org>
Cc: Ørjan Eide <orjan.eide at arm.com>
Cc: Robin Murphy <robin.murphy at arm.com>
Cc: Ezequiel Garcia <ezequiel at collabora.com>
Cc: Simon Ser <contact at emersion.fr>
Cc: James Jones <jajones at nvidia.com>
Cc: linux-media at vger.kernel.org
Cc: dri-devel at lists.freedesktop.org
Suggested-by: Suren Baghdasaryan <surenb at google.com>
Signed-off-by: John Stultz <john.stultz at linaro.org>
---
 drivers/dma-buf/heaps/cma_heap.c    | 1 +
 drivers/dma-buf/heaps/system_heap.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c
index 364fc2f3e499..0c76cbc3fb11 100644
--- a/drivers/dma-buf/heaps/cma_heap.c
+++ b/drivers/dma-buf/heaps/cma_heap.c
@@ -232,6 +232,7 @@ static void cma_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map)
 	struct cma_heap_buffer *buffer = dmabuf->priv;
 
 	mutex_lock(&buffer->lock);
+	WARN_ON(buffer->vmap_cnt == 0);
 	if (!--buffer->vmap_cnt) {
 		vunmap(buffer->vaddr);
 		buffer->vaddr = NULL;
diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 405351aad2a8..2321c91891f6 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -273,6 +273,7 @@ static void system_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map)
 	struct system_heap_buffer *buffer = dmabuf->priv;
 
 	mutex_lock(&buffer->lock);
+	WARN_ON(buffer->vmap_cnt == 0);
 	if (!--buffer->vmap_cnt) {
 		vunmap(buffer->vaddr);
 		buffer->vaddr = NULL;
-- 
2.17.1



More information about the dri-devel mailing list