Skip to content

Commit 9f81215

Browse files
authored
[UR][L0] Fix ext_ctl coverity bug (#19657)
Fix parameter validation before dereferencing an argument.
1 parent c438785 commit 9f81215

File tree

1 file changed

+4
-9
lines changed
  • unified-runtime/source/adapters/level_zero

1 file changed

+4
-9
lines changed

unified-runtime/source/adapters/level_zero/usm.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -925,20 +925,15 @@ umf_result_t L0MemoryProvider::ext_ctl(umf_ctl_query_source_t /*Source*/,
925925
const char *Name, void *Arg, size_t Size,
926926
umf_ctl_query_type_t /*QueryType*/,
927927
va_list /*Args*/) {
928-
if (std::string(Name) == "stats.allocated_memory") {
929-
if (!Arg && Size < sizeof(size_t)) {
930-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
931-
}
928+
if (!Arg || Size < sizeof(size_t)) {
929+
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
930+
}
932931

932+
if (std::string(Name) == "stats.allocated_memory") {
933933
*(reinterpret_cast<size_t *>(Arg)) = AllocStats.getCurrent();
934934
UR_LOG(DEBUG, "L0MemoryProvider::ext_ctl with name: {}, value: {}", Name,
935935
AllocStats.getCurrent());
936936
} else if (std::string(Name) == "stats.peak_memory") {
937-
if (!Arg && Size < sizeof(size_t)) {
938-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
939-
}
940-
941-
// Return the peak memory size.
942937
*(reinterpret_cast<size_t *>(Arg)) = AllocStats.getPeak();
943938
UR_LOG(DEBUG, "L0MemoryProvider::ext_ctl with name: {}, value: {}", Name,
944939
AllocStats.getPeak());

0 commit comments

Comments
 (0)