From 4f6a855f416276160d114c2ee6ebd9192e08f3a6 Mon Sep 17 00:00:00 2001 From: Zhou_Tao Date: Thu, 22 Aug 2024 10:17:26 +0800 Subject: [PATCH] [CP] Fix some potential Coverity issues2 Fix some potential Coverity issues of dereference before null check. --- .../linux/common/cp/ddi/media_ddi_prot.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/media_driver/linux/common/cp/ddi/media_ddi_prot.cpp b/media_driver/linux/common/cp/ddi/media_ddi_prot.cpp index 7546df05cca..159af93d180 100644 --- a/media_driver/linux/common/cp/ddi/media_ddi_prot.cpp +++ b/media_driver/linux/common/cp/ddi/media_ddi_prot.cpp @@ -96,7 +96,6 @@ VAStatus DdiMediaProtected::DdiMedia_CreateProtectedSession( if (cpCaps->IsCpConfigId(config_id)) { DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT); - DDI_CHK_NULL(prot, "nullptr prot", VA_STATUS_ERROR_ALLOCATION_FAILED); vaStatus = prot->CreateProtectedSession(ctx, config_id - DDI_CP_GEN_CONFIG_ATTRIBUTES_BASE, protected_session); } @@ -122,11 +121,11 @@ VAStatus DdiMediaProtected::DdiMedia_DestroyProtectedSession( VAStatus vaStatus = VA_STATUS_SUCCESS; uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; void *ctxPtr = DdiMedia_GetContextFromProtectedSessionID(ctx, protected_session, &ctxType); + DDI_CHK_NULL(ctxPtr, "nullptr prot", VA_STATUS_ERROR_INVALID_CONTEXT); if (ctxType == DDI_MEDIA_CONTEXT_TYPE_PROTECTED_CONTENT) { DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT); - DDI_CHK_NULL(prot, "nullptr prot", VA_STATUS_ERROR_ALLOCATION_FAILED); vaStatus = prot->DestroyProtectedSession(ctx, protected_session); } @@ -156,7 +155,6 @@ VAStatus DdiMediaProtected::DdiMedia_AttachProtectedSession( if (ctxType == DDI_MEDIA_CONTEXT_TYPE_PROTECTED_CONTENT) { DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT); - DDI_CHK_NULL(prot, "nullptr prot", VA_STATUS_ERROR_ALLOCATION_FAILED); vaStatus = prot->AttachProtectedSession(ctx, context, protected_session); } @@ -218,7 +216,6 @@ VAStatus DdiMediaProtected::DdiMedia_ProtectedSessionExecute( if (ctxType == DDI_MEDIA_CONTEXT_TYPE_PROTECTED_CONTENT) { DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT); - DDI_CHK_NULL(prot, "nullptr prot", VA_STATUS_ERROR_ALLOCATION_FAILED); vaStatus = prot->ProtectedSessionExecute(ctx, protected_session, data); } @@ -243,6 +240,8 @@ VAStatus DdiMediaProtected::DdiMedia_ProtectedSessionCreateBuffer( DDI_FUNCTION_ENTER(); DDI_CHK_NULL(ctx, "nullptr ctx", VA_STATUS_ERROR_INVALID_CONTEXT); + DDI_CHK_NULL(data, "nullptr data", VA_STATUS_ERROR_INVALID_PARAMETER); + DDI_CHK_NULL(bufId, "nullptr bufId", VA_STATUS_ERROR_INVALID_PARAMETER); VAStatus vaStatus = VA_STATUS_SUCCESS; uint32_t ctxType = DDI_MEDIA_CONTEXT_TYPE_NONE; @@ -252,7 +251,6 @@ VAStatus DdiMediaProtected::DdiMedia_ProtectedSessionCreateBuffer( if (ctxType == DDI_MEDIA_CONTEXT_TYPE_PROTECTED_CONTENT) { DdiMediaProtected *prot = DdiMediaProtected::GetInstance(DDI_PROTECTED_CONTENT); - DDI_CHK_NULL(prot, "nullptr prot", VA_STATUS_ERROR_ALLOCATION_FAILED); vaStatus = prot->ProtectedSessionCreateBuffer(ctx, context, type, size, num_elements, data, bufId); } @@ -326,6 +324,12 @@ void DdiMedia_FreeProtectedSessionHeap( int32_t vaContextOffset, int32_t ctxNums) { + if (nullptr == ctx || nullptr == contextHeap) + { + DDI_ASSERTMESSAGE("DDI: Invalid input arguments"); + return; + } + PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT mediaContextHeapBase = (PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT)contextHeap->pHeapBase; if (nullptr == mediaContextHeapBase) return; @@ -353,6 +357,12 @@ static void* DdiMedia_GetVaContextFromHeap( uint32_t index, PMEDIA_MUTEX_T mutex) { + if (nullptr == mutex) + { + DDI_ASSERTMESSAGE("DDI: Invalid input arguments"); + return nullptr; + } + PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT vaCtxHeapElmt = nullptr; void *context = nullptr;