From c03ccd89c24572dcb65bdfc8d9ab5eb76da28c96 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 13 Sep 2017 14:03:34 -0700 Subject: gpu: nvgpu: Add nvgpu_mem_is_valid() call Add a function to check if an nvgpu_mem is allocated (valid) or not. Also fix possibly leaked state in nvgpu_mems when they fail to allocate. Also ensure that in the case of a failure to allocate no state is accidentally leaked to the caller. This should hopefully make it less likely that a caller thinks a buffer that failed to allocate is actually allocated. Change-Id: I43224ece7da84e63b2f43f36f04941126fabf3c7 Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1559419 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/linux/dma.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/gpu/nvgpu/common/linux') diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c index 13c1c347..43009fca 100644 --- a/drivers/gpu/nvgpu/common/linux/dma.c +++ b/drivers/gpu/nvgpu/common/linux/dma.c @@ -167,6 +167,7 @@ fail_free: dma_free_coherent(d, size, mem->cpu_va, iova); mem->cpu_va = NULL; mem->priv.sgt = NULL; + mem->size = 0; return err; } @@ -253,6 +254,7 @@ fail_kfree: nvgpu_kfree(g, mem->priv.sgt); fail_physfree: nvgpu_free(&g->mm.vidmem.allocator, addr); + mem->size = 0; return err; #else return -ENOSYS; -- cgit v1.2.2