Skip to content

Commit dfa6faf

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
fix: validate event pool count
Related-To: GSD-13399 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com> Source: 0d1f386
1 parent dc445d3 commit dfa6faf

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎level_zero/core/source/event/event.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ template Event *Event::create<uint64_t>(const EventDescriptor &, Device *, ze_re
4040
template Event *Event::create<uint32_t>(const EventDescriptor &, Device *, ze_result_t &);
4141

4242
ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32_t numDevices, ze_device_handle_t *deviceHandles) {
43+
if (this->numEvents == 0) {
44+
return ZE_RESULT_ERROR_INVALID_SIZE;
45+
}
46+
4347
this->context = context;
4448

4549
const bool counterBased = (counterBasedFlags != 0);

‎level_zero/core/test/unit_tests/sources/event/test_event.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ TEST_F(EventPoolFailTests, givenEnabledTimestampPoolAllocatorWhenCreatingEventPo
223223
EXPECT_EQ(res, ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY);
224224
}
225225

226+
TEST_F(EventPoolCreate, givenZeroEventCountWhenCreatingEventPoolThenInvalidSizeIsReturned) {
227+
ze_event_pool_desc_t eventPoolDesc = {
228+
ZE_STRUCTURE_TYPE_EVENT_POOL_DESC,
229+
nullptr,
230+
0,
231+
0};
232+
233+
ze_result_t result = ZE_RESULT_SUCCESS;
234+
std::unique_ptr<L0::EventPool> eventPool(EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
235+
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_SIZE, result);
236+
EXPECT_EQ(nullptr, eventPool);
237+
}
238+
226239
TEST_F(EventPoolCreate, GivenEventPoolThenAllocationContainsAtLeast16Bytes) {
227240
ze_event_pool_desc_t eventPoolDesc = {
228241
ZE_STRUCTURE_TYPE_EVENT_POOL_DESC,

0 commit comments

Comments
 (0)