From 16fc6e3931733c9d5ff87e0b889aa2b897c540c3 Mon Sep 17 00:00:00 2001 From: Konsta Holtta Date: Thu, 30 Apr 2015 13:30:05 +0300 Subject: gpu: nvgpu: protect missing sgl in gk20a_mem_phys Return zero for missing sgl (sgt is already checked) instead of attempting to dereference NULL. Those NULL conditions should be almost nonexistent, and zero is not normally used. When reading gk20a_mem_phys() in gk20a_gr_get_chid_from_ctx() from an isr, the mem desc may race with channel deletion and get suddendly zeroed, even if the channel's in_use flag would be set. Plain zero results in expected behaviour. Change-Id: I7033979091951cba3e3004ddc7550cd327ad0baf Signed-off-by: Konsta Holtta Reviewed-on: http://git-master/r/737759 Reviewed-by: Terje Bergstrom Tested-by: Terje Bergstrom --- drivers/gpu/nvgpu/gk20a/mm_gk20a.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/mm_gk20a.h') diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h index e07b95fe..c1f8a4f0 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.h @@ -464,9 +464,17 @@ void gk20a_gmmu_free_attr(struct gk20a *g, static inline phys_addr_t gk20a_mem_phys(struct mem_desc *mem) { - /* the sgt may get null if this is accessed e.g. in an isr during - * channel deletion */ - return mem->sgt ? sg_phys(mem->sgt->sgl) : 0; + /* FIXME: the sgt/sgl may get null if this is accessed e.g. in an isr + * during channel deletion - attempt to fix at least null derefs */ + struct sg_table *sgt = mem->sgt; + + if (sgt) { + struct scatterlist *sgl = sgt->sgl; + if (sgl) + return sg_phys(sgl); + } + + return 0; } u64 gk20a_locked_gmmu_map(struct vm_gk20a *vm, -- cgit v1.2.2