From 39367df58725d82e035e83105709c9441ddf8783 Mon Sep 17 00:00:00 2001 From: Roy Pledge Date: Mon, 31 Mar 2014 15:12:07 -0400 Subject: Reduce reference count of DMA memory fragments during unmap If a process explictly unmapped DMA fragments the reference count of each fragement wasn't properly decremented causing a leak. This would only occur if the proccess explicitly umapped the memory, exiting the process did correctly adjust the reference counts Signed-off-by: Roy Pledge Change-Id: Ia9adfccd5249d17d5506796b1fe71c32f46cab30 Reviewed-on: http://git.am.freescale.net:8181/10527 Tested-by: Review Code-CDREVIEW Reviewed-by: Geoff Thorpe Reviewed-by: Jose Rivera diff --git a/drivers/staging/fsl_qbman/fsl_usdpaa.c b/drivers/staging/fsl_qbman/fsl_usdpaa.c index 0e6adca..dbbc80f 100644 --- a/drivers/staging/fsl_qbman/fsl_usdpaa.c +++ b/drivers/staging/fsl_qbman/fsl_usdpaa.c @@ -1009,7 +1009,8 @@ static long ioctl_dma_unmap(struct ctx *ctx, void __user *arg) { struct mem_mapping *map; struct vm_area_struct *vma; - int ret; + int ret, i; + struct mem_fragment *current_frag; down_write(¤t->mm->mmap_sem); vma = find_vma(current->mm, (unsigned long)arg); @@ -1031,6 +1032,13 @@ static long ioctl_dma_unmap(struct ctx *ctx, void __user *arg) } map = NULL; map_match: + current_frag = map->root_frag; + for (i = 0; i < map->frag_count; i++) { + DPA_ASSERT(current_frag->refs > 0); + --current_frag->refs; + current_frag = list_entry(current_frag->list.prev, + struct mem_fragment, list); + } list_del(&map->list); compress_frags(); spin_unlock(&mem_lock); -- cgit v0.10.2