Skip to content

Commit bd63464

Browse files
omarahmed1111kbenzie
authored andcommitted
Merge pull request #1955 from nrspruit/fix_l0_coverity
[L0] fix Coverity issues for L0 Adapter
1 parent 5020f1e commit bd63464

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

source/adapters/level_zero/event.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ ur_result_t urEventReleaseInternal(ur_event_handle_t Event) {
10341034
EndTimeRecording.EventHasDied = true;
10351035
} else {
10361036
// Otherwise we evict the entry.
1037-
Legacy(Event->UrQueue)->EndTimeRecordings.erase(Entry);
1037+
Queue->EndTimeRecordings.erase(Entry);
10381038
}
10391039
}
10401040
}

source/adapters/level_zero/image.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesImportExternalMemoryExp(
10331033
break;
10341034
case UR_EXP_EXTERNAL_MEM_TYPE_OPAQUE_FD:
10351035
default:
1036+
delete importWin32;
1037+
delete externalMemoryData;
10361038
return UR_RESULT_ERROR_INVALID_VALUE;
10371039
}
10381040
importWin32->handle = Win32Handle->handle;

source/adapters/level_zero/queue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ ur_result_t ur_queue_handle_legacy_t_::queueRelease() {
607607
// internal reference count. When the External Reference count == 0, then
608608
// cleanup of the queue begins and the final decrement of the internal
609609
// reference count is completed.
610-
Queue->RefCount.decrementAndTest();
610+
static_cast<void>(Queue->RefCount.decrementAndTest());
611611
return UR_RESULT_SUCCESS;
612612
}
613613

source/adapters/level_zero/usm.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMHostAlloc(
311311
// L0 supports alignment up to 64KB and silently ignores higher values.
312312
// We flag alignment > 64KB as an invalid value.
313313
// L0 spec says that alignment values that are not powers of 2 are invalid.
314-
if (Align > 65536 || (Align & (Align - 1)) != 0)
315-
return UR_RESULT_ERROR_INVALID_VALUE;
314+
// If alignment == 0, then we are allowing the L0 driver to choose the
315+
// alignment so no need to check.
316+
if (Align > 0) {
317+
if (Align > 65536 || (Align & (Align - 1)) != 0)
318+
return UR_RESULT_ERROR_INVALID_VALUE;
319+
}
316320

317321
ur_platform_handle_t Plt = Context->getPlatform();
318322
// If indirect access tracking is enabled then lock the mutex which is
@@ -381,8 +385,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMDeviceAlloc(
381385
// L0 supports alignment up to 64KB and silently ignores higher values.
382386
// We flag alignment > 64KB as an invalid value.
383387
// L0 spec says that alignment values that are not powers of 2 are invalid.
384-
if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0)
385-
return UR_RESULT_ERROR_INVALID_VALUE;
388+
// If alignment == 0, then we are allowing the L0 driver to choose the
389+
// alignment so no need to check.
390+
if (Alignment > 0) {
391+
if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0)
392+
return UR_RESULT_ERROR_INVALID_VALUE;
393+
}
386394

387395
ur_platform_handle_t Plt = Device->Platform;
388396

@@ -482,8 +490,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urUSMSharedAlloc(
482490
// L0 supports alignment up to 64KB and silently ignores higher values.
483491
// We flag alignment > 64KB as an invalid value.
484492
// L0 spec says that alignment values that are not powers of 2 are invalid.
485-
if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0)
486-
return UR_RESULT_ERROR_INVALID_VALUE;
493+
// If alignment == 0, then we are allowing the L0 driver to choose the
494+
// alignment so no need to check.
495+
if (Alignment > 0) {
496+
if (Alignment > 65536 || (Alignment & (Alignment - 1)) != 0)
497+
return UR_RESULT_ERROR_INVALID_VALUE;
498+
}
487499

488500
ur_platform_handle_t Plt = Device->Platform;
489501

0 commit comments

Comments
 (0)