From 6d65e58fd2208dafe76a6a330a21f9e1b0e296cc Mon Sep 17 00:00:00 2001 From: Divya Date: Tue, 28 Feb 2023 07:11:48 +0000 Subject: [PATCH] gpu: nvgpu fix coverity issue in therm/cg unit Add NULL check for ELCG and BLCG HALs based on cgmode to avoid coverity issue: CWE-476: NULL Pointer Dereference Bug 3952896 Change-Id: I3ee717645bbecaafddb5d485f57550e213bf762b Signed-off-by: Divya Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2864656 Reviewed-by: svcacv Reviewed-by: Sagar Kamble Reviewed-by: Mahantesh Kumbar Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/power_features/cg/cg.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/common/power_features/cg/cg.c b/drivers/gpu/nvgpu/common/power_features/cg/cg.c index 6af384f46..a22856b8e 100644 --- a/drivers/gpu/nvgpu/common/power_features/cg/cg.c +++ b/drivers/gpu/nvgpu/common/power_features/cg/cg.c @@ -33,8 +33,13 @@ static void nvgpu_cg_set_mode(struct gk20a *g, u32 cgmode, u32 mode_config) const struct nvgpu_device *dev = NULL; struct nvgpu_fifo *f = &g->fifo; - if ((g->ops.therm.init_blcg_mode == NULL) && - (g->ops.therm.init_elcg_mode == NULL)) { + /* + * Add NULL check for ELCG and BLCG HALs based on cgmode + * to avoid coverity issue: CWE-476: NULL Pointer Dereference + */ + if ((cgmode == BLCG_MODE && g->ops.therm.init_blcg_mode == NULL) || + (cgmode == ELCG_MODE && + g->ops.therm.init_elcg_mode == NULL)) { return; }