From 11d27743f81e5313cb09ca12272bbf23d6c936f1 Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Wed, 26 May 2021 16:31:39 +0530 Subject: [PATCH] gpu: nvgpu: add NULL checks before freeing ZBC and ZCULL Disabling NVGPU_SUPPORT_MIG in suspend path leads to inconsistencies. During driver removal without the flag set, the driver still tries to free structures that might not have been allocated in the first place. e.g. nvgpu_gr_zbc_deinit, nvgpu_gr_zcull_deinit. Added NULL checks for ZBC and ZCULL structures before freeing them as a solution. Jira NVGPU-6832 Change-Id: I8a0c64ca982d11fee55542abd3c5bce5a51b4007 Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2535101 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: svc_kernel_abi Reviewed-by: Lakshmanan M Reviewed-by: Dinesh T Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/gr/zbc.c | 4 ++++ drivers/gpu/nvgpu/common/gr/zcull.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/common/gr/zbc.c b/drivers/gpu/nvgpu/common/gr/zbc.c index f0f6d832e..8299dfdc0 100644 --- a/drivers/gpu/nvgpu/common/gr/zbc.c +++ b/drivers/gpu/nvgpu/common/gr/zbc.c @@ -602,6 +602,10 @@ alloc_err: /* deallocate the memory for the struct */ void nvgpu_gr_zbc_deinit(struct gk20a *g, struct nvgpu_gr_zbc *zbc) { + if (zbc == NULL) { + return; + } + nvgpu_kfree(g, zbc->zbc_col_tbl); nvgpu_kfree(g, zbc->zbc_dep_tbl); nvgpu_kfree(g, zbc->zbc_s_tbl); diff --git a/drivers/gpu/nvgpu/common/gr/zcull.c b/drivers/gpu/nvgpu/common/gr/zcull.c index 511022239..e86cf9562 100644 --- a/drivers/gpu/nvgpu/common/gr/zcull.c +++ b/drivers/gpu/nvgpu/common/gr/zcull.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2019-2021, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -72,6 +72,10 @@ exit: void nvgpu_gr_zcull_deinit(struct gk20a *g, struct nvgpu_gr_zcull *gr_zcull) { + if (gr_zcull == NULL) { + return; + } + nvgpu_kfree(g, gr_zcull); }