Skip to content

Commit a9b64bb

Browse files
authored
[Offload] Fix segfault when looking for host device name (#141632)
Summary: This is done using the generic device into pointe, but no such thing exists for the host device, leading to a segfault. This patch fixes that for now, but in the future we should probably be more careful in general handling the possibility that the handle is null everywhere. Fixes: #141434
1 parent 20f9f1f commit a9b64bb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

offload/liboffload/src/OffloadImpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ Error olGetDeviceInfoImplDetail(ol_device_handle_t Device,
230230
// Find the info if it exists under any of the given names
231231
auto GetInfo = [&](std::vector<std::string> Names) {
232232
InfoQueueTy DevInfo;
233+
if (Device == HostDevice())
234+
return std::string("Host");
235+
236+
if (!Device->Device)
237+
return std::string("");
238+
233239
if (auto Err = Device->Device->obtainInfoImpl(DevInfo))
234240
return std::string("");
235241

offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ TEST_P(olGetDeviceInfoTest, SuccessName) {
3737
ASSERT_EQ(std::strlen(Name.data()), Size - 1);
3838
}
3939

40+
TEST_P(olGetDeviceInfoTest, HostName) {
41+
size_t Size = 0;
42+
ASSERT_SUCCESS(olGetDeviceInfoSize(Host, OL_DEVICE_INFO_NAME, &Size));
43+
ASSERT_GT(Size, 0ul);
44+
std::vector<char> Name;
45+
Name.resize(Size);
46+
ASSERT_SUCCESS(olGetDeviceInfo(Host, OL_DEVICE_INFO_NAME, Size, Name.data()));
47+
ASSERT_EQ(std::strlen(Name.data()), Size - 1);
48+
}
49+
4050
TEST_P(olGetDeviceInfoTest, SuccessVendor) {
4151
size_t Size = 0;
4252
ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_VENDOR, &Size));

0 commit comments

Comments
 (0)