Skip to content

Commit 6d49f27

Browse files
authored
[UR] Fix some issues in CL PlatformGet turned up by static analysis. (#19002)
1 parent 4673ca4 commit 6d49f27

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

unified-runtime/source/adapters/opencl/platform.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ urPlatformGet(ur_adapter_handle_t, uint32_t NumEntries,
7272
static std::mutex adapterPopulationMutex{};
7373
ur_adapter_handle_t Adapter = nullptr;
7474
UR_RETURN_ON_FAILURE(urAdapterGet(1, &Adapter, nullptr));
75-
if (Adapter && !(Adapter->NumPlatforms)) {
75+
if (!Adapter) {
76+
// The only operation urAdapterGet really performs is allocating the adapter
77+
// handle via new, so no adapter handle here almost certainly means memory
78+
// problems.
79+
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
80+
}
81+
82+
if (Adapter->NumPlatforms == 0) {
7683
std::lock_guard guard{adapterPopulationMutex};
7784

7885
// It's possible for urPlatformGet, if ran on multiple threads, to enter

0 commit comments

Comments
 (0)