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 <ybhosale@nvidia.com>
Reviewed-on: http://git-master/r/777118
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
This commit is contained in:
Yogesh
2015-07-30 21:02:11 -07:00
committed by Terje Bergstrom
parent 9cf28bc529
commit 77e608d528
2 changed files with 17 additions and 12 deletions

View File

@@ -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;
}

View File

@@ -2286,7 +2286,8 @@ void gk20a_remove_pmu_support(struct pmu_gk20a *pmu)
{
gk20a_dbg_fn("");
gk20a_allocator_destroy(&pmu->dmem);
if (pmu->dmem.init)
gk20a_allocator_destroy(&pmu->dmem);
}
static int gk20a_init_pmu_reset_enable_hw(struct gk20a *g)