From 50975dcf2afe7b8111d228e1520f652ac7ebe061 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Mon, 9 Oct 2017 15:06:26 -0700 Subject: gpu: nvgpu: memset alloced buffers on free When freeing kmalloc and vmalloc buffers memset them to zero before freeing them with the kernel APIs. This is only done if CONFIG_NVGPU_TRACK_MEM_USAGE is set since this adds obvious overhead to the driver. However, it is an incredibly useful debug tool, so it's nice to have. This could be done by enabling Linux kernel configs as well, but not all OSes may have such a feature so building it into nvgpu may prove quite useful. Change-Id: I7a6a9a6ab4f3606a73a90b354c5a4a7b9cd4d947 Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1575565 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svccoveritychecker Reviewed-by: Konsta Holtta GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom --- drivers/gpu/nvgpu/common/linux/kmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/kmem.c b/drivers/gpu/nvgpu/common/linux/kmem.c index 04df552c..a492fb35 100644 --- a/drivers/gpu/nvgpu/common/linux/kmem.c +++ b/drivers/gpu/nvgpu/common/linux/kmem.c @@ -301,6 +301,8 @@ static int __nvgpu_free_kmem_alloc(struct nvgpu_mem_alloc_tracker *tracker, return -EINVAL; } + memset((void *)alloc->addr, 0, alloc->size); + tracker->nr_frees++; tracker->bytes_freed += alloc->size; tracker->bytes_freed_real += alloc->real_size; @@ -415,9 +417,9 @@ void __nvgpu_track_vfree(struct gk20a *g, void *addr) if (!addr) return; - vfree(addr); - __nvgpu_free_kmem_alloc(g->vmallocs, (u64)(uintptr_t)addr); + + vfree(addr); } void __nvgpu_track_kfree(struct gk20a *g, void *addr) @@ -425,9 +427,9 @@ void __nvgpu_track_kfree(struct gk20a *g, void *addr) if (!addr) return; - kfree(addr); - __nvgpu_free_kmem_alloc(g->kmallocs, (u64)(uintptr_t)addr); + + kfree(addr); } static int __do_check_for_outstanding_allocs( -- cgit v1.2.2