From 237c84a879db5dbc77f5a43d6477c3c00b20e8c8 Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Thu, 29 Aug 2019 17:42:35 -0400 Subject: [PATCH] gpu: nvgpu: add NULL check in nvgpu_ecc_free gr_config can be NULL in nvgpu_ecc_free. This happens when kernel module is unloaded without ever powering on the GPU. Check that gr_config is not NULL, before calling nvgpu_gr_config_get_gpc_count. Bug 2691108 Change-Id: Ic0ebeb3e1d283464242d8487c2f4a1bb88920f8a Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/2186647 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: Alex Waterman GVS: Gerrit_Virtual_Submit Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/ecc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/common/ecc.c b/drivers/gpu/nvgpu/common/ecc.c index 13d9aff40..b093f556c 100644 --- a/drivers/gpu/nvgpu/common/ecc.c +++ b/drivers/gpu/nvgpu/common/ecc.c @@ -215,9 +215,15 @@ void nvgpu_ecc_free(struct gk20a *g) { struct nvgpu_ecc *ecc = &g->ecc; struct nvgpu_gr_config *gr_config = nvgpu_gr_get_config_ptr(g); - u32 gpc_count = nvgpu_gr_config_get_gpc_count(gr_config); + u32 gpc_count; u32 i; + if (gr_config == NULL) { + return; + } + + gpc_count = nvgpu_gr_config_get_gpc_count(gr_config); + for (i = 0; i < gpc_count; i++) { if (ecc->gr.sm_lrf_ecc_single_err_count != NULL) { nvgpu_kfree(g, ecc->gr.sm_lrf_ecc_single_err_count[i]);