From 77e608d528b85d9b63bef90606afbcd8504e16d1 Mon Sep 17 00:00:00 2001 From: Yogesh Date: Thu, 30 Jul 2015 21:02:11 -0700 Subject: gpu: nvgpu: Check for valid memory pointers 1. Before destroying the allocator for PMU dmem check if it was already initialized. It is only initialized through certain paths like PMU ISRs. So while testing the nvgpu module using nvgpu_submit_twod test I found that it was never initialized. 2. Inside gk20a_init_gr_setup_sw, cleanup part calls for de-allocating the already allocated chunk of memory. Whereas, cleanup also gets called when memory allocation inside the same function fails. In such cases, we should have a non-null check else we attempt to free a non-allocated memory and kernel panics. Bug 1476801 Change-Id: Ia2f0599ac0c35d58709acd149033e114b898b426 Signed-off-by: Yogesh Bhosale Reviewed-on: http://git-master/r/777118 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/mm_gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index 32ccc5b8..b12091bf 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c @@ -1898,19 +1898,23 @@ void gk20a_gmmu_free_attr(struct gk20a *g, enum dma_attr attr, if (attr) { DEFINE_DMA_ATTRS(attrs); dma_set_attr(attr, &attrs); - if (attr == DMA_ATTR_NO_KERNEL_MAPPING) - dma_free_attrs(d, mem->size, mem->pages, - sg_dma_address(mem->sgt->sgl), - &attrs); - else - dma_free_attrs(d, mem->size, mem->cpu_va, - sg_dma_address(mem->sgt->sgl), - &attrs); + if (attr == DMA_ATTR_NO_KERNEL_MAPPING) { + if (mem->pages) + dma_free_attrs(d, mem->size, mem->pages, + sg_dma_address(mem->sgt->sgl), + &attrs); + } else { + if (mem->cpu_va) + dma_free_attrs(d, mem->size, + mem->cpu_va, + sg_dma_address(mem->sgt->sgl), + &attrs); + } } else { - dma_free_coherent(d, mem->size, mem->cpu_va, - sg_dma_address(mem->sgt->sgl)); + if (mem->cpu_va) + dma_free_coherent(d, mem->size, mem->cpu_va, + sg_dma_address(mem->sgt->sgl)); } - mem->cpu_va = NULL; mem->pages = NULL; } -- cgit v1.2.2