From 4dee4196d959974ef4b7e45931d7f8732ffe61b5 Mon Sep 17 00:00:00 2001 From: Krzysztof Swiecicki Date: Tue, 17 Feb 2026 09:31:43 +0000 Subject: [PATCH] [UR] Coverity fixes Fixed uncaught exception in destructor, breaking rule of three, and potential null dereference issues. --- unified-runtime/include/ur_api.h | 4 ++++ unified-runtime/scripts/core/exp-bindless-images.yml | 4 ++++ .../source/adapters/level_zero/image_common.cpp | 2 +- unified-runtime/source/adapters/level_zero/v2/graph.cpp | 5 +++-- unified-runtime/source/adapters/level_zero/v2/graph.hpp | 8 ++++++++ .../source/loader/layers/validation/ur_valddi.cpp | 6 ++++++ unified-runtime/source/loader/ur_libapi.cpp | 4 ++++ unified-runtime/source/ur_api.cpp | 4 ++++ 8 files changed, 34 insertions(+), 3 deletions(-) diff --git a/unified-runtime/include/ur_api.h b/unified-runtime/include/ur_api.h index c401934937c9e..fdd5604d97216 100644 --- a/unified-runtime/include/ur_api.h +++ b/unified-runtime/include/ur_api.h @@ -10420,6 +10420,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp( /// pDstImageDesc->type` /// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE /// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +/// + `phEventWaitList == NULL && numEventsInWaitList > 0` +/// + `phEventWaitList != NULL && numEventsInWaitList == 0` +/// + If event objects in phEventWaitList are not valid events. UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImageCopyExp( /// [in] handle of the queue object ur_queue_handle_t hQueue, diff --git a/unified-runtime/scripts/core/exp-bindless-images.yml b/unified-runtime/scripts/core/exp-bindless-images.yml index 05c6acec0191f..9a1e89d77ea99 100644 --- a/unified-runtime/scripts/core/exp-bindless-images.yml +++ b/unified-runtime/scripts/core/exp-bindless-images.yml @@ -641,6 +641,10 @@ returns: - "`pDstImageDesc && UR_MEM_TYPE_IMAGE_CUBEMAP_EXP < pDstImageDesc->type`" - $X_RESULT_ERROR_INVALID_IMAGE_SIZE - $X_RESULT_ERROR_INVALID_OPERATION + - $X_RESULT_ERROR_INVALID_EVENT_WAIT_LIST: + - "`phEventWaitList == NULL && numEventsInWaitList > 0`" + - "`phEventWaitList != NULL && numEventsInWaitList == 0`" + - "If event objects in phEventWaitList are not valid events." --- #-------------------------------------------------------------------------- type: function desc: "Query an image memory handle for specific properties" diff --git a/unified-runtime/source/adapters/level_zero/image_common.cpp b/unified-runtime/source/adapters/level_zero/image_common.cpp index 21ed10601234b..699e4af746639 100644 --- a/unified-runtime/source/adapters/level_zero/image_common.cpp +++ b/unified-runtime/source/adapters/level_zero/image_common.cpp @@ -815,7 +815,7 @@ ur_result_t bindlessImagesHandleCopyFlags( uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) { ZeStruct zeSrcImageDesc; - ur2zeImageDesc(pSrcImageFormat, pSrcImageDesc, zeSrcImageDesc); + UR_CALL(ur2zeImageDesc(pSrcImageFormat, pSrcImageDesc, zeSrcImageDesc)); uint32_t SrcPixelSizeInBytes = getPixelSizeBytes(pSrcImageFormat); uint32_t DstPixelSizeInBytes = getPixelSizeBytes(pDstImageFormat); diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.cpp b/unified-runtime/source/adapters/level_zero/v2/graph.cpp index 3023570966bd6..1bedfbd3edb3b 100644 --- a/unified-runtime/source/adapters/level_zero/v2/graph.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/graph.cpp @@ -29,7 +29,7 @@ ur_exp_graph_handle_t_::~ur_exp_graph_handle_t_() { ze_result_t ZeResult = ZE_CALL_NOCHECK( hContext->getPlatform()->ZeGraphExt.zeGraphDestroyExp, (zeGraph)); if (ZeResult != ZE_RESULT_SUCCESS) { - UR_LOG(WARN, "Failed to destroy graph handle: {}", ZeResult); + UR_LOG_SAFE(WARN, "Failed to destroy graph handle: {}", ZeResult); } } } @@ -48,7 +48,8 @@ ur_exp_executable_graph_handle_t_::~ur_exp_executable_graph_handle_t_() { hContext->getPlatform()->ZeGraphExt.zeExecutableGraphDestroyExp, (zeExGraph)); if (ZeResult != ZE_RESULT_SUCCESS) { - UR_LOG(WARN, "Failed to destroy executable graph handle: {}", ZeResult); + UR_LOG_SAFE(WARN, "Failed to destroy executable graph handle: {}", + ZeResult); } } } diff --git a/unified-runtime/source/adapters/level_zero/v2/graph.hpp b/unified-runtime/source/adapters/level_zero/v2/graph.hpp index 178c206719833..0b6b62da1aa22 100644 --- a/unified-runtime/source/adapters/level_zero/v2/graph.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/graph.hpp @@ -21,6 +21,9 @@ struct ur_exp_graph_handle_t_ : ur_object { ze_graph_handle_t zeGraph); ~ur_exp_graph_handle_t_(); + ur_exp_graph_handle_t_(const ur_exp_graph_handle_t_ &) = delete; + ur_exp_graph_handle_t_ &operator=(const ur_exp_graph_handle_t_ &) = delete; + ze_graph_handle_t getZeHandle() { return zeGraph; } ur_context_handle_t getContext() { return hContext; } @@ -35,6 +38,11 @@ struct ur_exp_executable_graph_handle_t_ : ur_object { ur_exp_graph_handle_t hGraph); ~ur_exp_executable_graph_handle_t_(); + ur_exp_executable_graph_handle_t_(const ur_exp_executable_graph_handle_t_ &) = + delete; + ur_exp_executable_graph_handle_t_ & + operator=(const ur_exp_executable_graph_handle_t_ &) = delete; + ze_executable_graph_handle_t &getZeHandle() { return zeExGraph; } ur_context_handle_t getContext() const { return hContext; } diff --git a/unified-runtime/source/loader/layers/validation/ur_valddi.cpp b/unified-runtime/source/loader/layers/validation/ur_valddi.cpp index a2f0b00f79a44..3a521e122a1d5 100644 --- a/unified-runtime/source/loader/layers/validation/ur_valddi.cpp +++ b/unified-runtime/source/loader/layers/validation/ur_valddi.cpp @@ -7948,6 +7948,12 @@ __urdlllocal ur_result_t UR_APICALL urBindlessImagesImageCopyExp( if (pDstImageDesc && UR_MEM_TYPE_IMAGE_CUBEMAP_EXP < pDstImageDesc->type) return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR; + if (phEventWaitList == NULL && numEventsInWaitList > 0) + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + + if (phEventWaitList != NULL && numEventsInWaitList == 0) + return UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST; + if (phEventWaitList != NULL && numEventsInWaitList > 0) { for (uint32_t i = 0; i < numEventsInWaitList; ++i) { if (phEventWaitList[i] == NULL) { diff --git a/unified-runtime/source/loader/ur_libapi.cpp b/unified-runtime/source/loader/ur_libapi.cpp index 1cae1d517729c..e88e0fcf1cacb 100644 --- a/unified-runtime/source/loader/ur_libapi.cpp +++ b/unified-runtime/source/loader/ur_libapi.cpp @@ -7738,6 +7738,10 @@ ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp( /// pDstImageDesc->type` /// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE /// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +/// + `phEventWaitList == NULL && numEventsInWaitList > 0` +/// + `phEventWaitList != NULL && numEventsInWaitList == 0` +/// + If event objects in phEventWaitList are not valid events. ur_result_t UR_APICALL urBindlessImagesImageCopyExp( /// [in] handle of the queue object ur_queue_handle_t hQueue, diff --git a/unified-runtime/source/ur_api.cpp b/unified-runtime/source/ur_api.cpp index acef3acd7a2b8..2564f09fffab9 100644 --- a/unified-runtime/source/ur_api.cpp +++ b/unified-runtime/source/ur_api.cpp @@ -6781,6 +6781,10 @@ ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp( /// pDstImageDesc->type` /// - ::UR_RESULT_ERROR_INVALID_IMAGE_SIZE /// - ::UR_RESULT_ERROR_INVALID_OPERATION +/// - ::UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST +/// + `phEventWaitList == NULL && numEventsInWaitList > 0` +/// + `phEventWaitList != NULL && numEventsInWaitList == 0` +/// + If event objects in phEventWaitList are not valid events. ur_result_t UR_APICALL urBindlessImagesImageCopyExp( /// [in] handle of the queue object ur_queue_handle_t hQueue,