From c32c4025a4c5e5e0466fb8ca05f3df5d68e736b3 Mon Sep 17 00:00:00 2001 From: Sagar Kamble Date: Thu, 5 May 2022 07:01:03 +0530 Subject: [PATCH] gpu: nvgpu: fix the ce app ctx cleanup tsg and ch members in ce_ctx may remain uninitialized when the cleanup function nvgpu_ce_delete_gpu_context_locked is called. Guard the references to those. CID 438091 Bug 3512546 Change-Id: I0ce96f9bad1e4f7fd331171b3f134c48c893839f Signed-off-by: Sagar Kamble Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2707470 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Sachin Nikam GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/ce/ce_app.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/nvgpu/common/ce/ce_app.c b/drivers/gpu/nvgpu/common/ce/ce_app.c index ecf1d0411..29bd1e719 100644 --- a/drivers/gpu/nvgpu/common/ce/ce_app.c +++ b/drivers/gpu/nvgpu/common/ce/ce_app.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2022, 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"), @@ -217,7 +217,6 @@ static void nvgpu_ce_delete_gpu_context_locked(struct nvgpu_ce_gpu_ctx *ce_ctx) struct nvgpu_list_node *list = &ce_ctx->list; ce_ctx->gpu_ctx_state = NVGPU_CE_GPU_CTX_DELETED; - ce_ctx->tsg->abortable = true; nvgpu_mutex_acquire(&ce_ctx->gpu_ctx_mutex); @@ -230,8 +229,14 @@ static void nvgpu_ce_delete_gpu_context_locked(struct nvgpu_ce_gpu_ctx *ce_ctx) * free the channel * nvgpu_channel_close() will also unbind the channel from TSG */ - nvgpu_channel_close(ce_ctx->ch); - nvgpu_ref_put(&ce_ctx->tsg->refcount, nvgpu_tsg_release); + if (ce_ctx->ch != NULL) { + nvgpu_channel_close(ce_ctx->ch); + } + + if (ce_ctx->tsg != NULL) { + ce_ctx->tsg->abortable = true; + nvgpu_ref_put(&ce_ctx->tsg->refcount, nvgpu_tsg_release); + } /* housekeeping on app */ if ((list->prev != NULL) && (list->next != NULL)) {