From 6f2a8e8a1c6ad58c906bbddc244358e9090ddb96 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 25 Jan 2021 13:17:51 +0000 Subject: [PATCH] Correct nullptr SVM arg handling Related-To: NEO-5001 Signed-off-by: Mateusz Jablonski --- opencl/source/kernel/svm_object_arg.cpp | 6 ++++-- .../unit_test/kernel/svm_object_arg_tests.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/opencl/source/kernel/svm_object_arg.cpp b/opencl/source/kernel/svm_object_arg.cpp index ed5a57c918..e946aa27ce 100644 --- a/opencl/source/kernel/svm_object_arg.cpp +++ b/opencl/source/kernel/svm_object_arg.cpp @@ -18,8 +18,10 @@ GraphicsAllocation *SvmObjectArg::getGraphicsAllocation(uint32_t rootDeviceIndex DEBUG_BREAK_IF(singleDeviceSvmAlloc && rootDeviceIndex != singleDeviceSvmAlloc->getRootDeviceIndex()); return singleDeviceSvmAlloc; } - UNRECOVERABLE_IF(!multiDeviceSvmAlloc); - return multiDeviceSvmAlloc->getGraphicsAllocation(rootDeviceIndex); + if (multiDeviceSvmAlloc) { + return multiDeviceSvmAlloc->getGraphicsAllocation(rootDeviceIndex); + } + return nullptr; } bool SvmObjectArg::isCoherent() const { diff --git a/opencl/test/unit_test/kernel/svm_object_arg_tests.cpp b/opencl/test/unit_test/kernel/svm_object_arg_tests.cpp index 01a3f69bb1..66c7a3075e 100644 --- a/opencl/test/unit_test/kernel/svm_object_arg_tests.cpp +++ b/opencl/test/unit_test/kernel/svm_object_arg_tests.cpp @@ -39,3 +39,18 @@ TEST(SvmObjectArgTest, givenMultiGraphicsAllocationWhenCreatingSvmObjectArgThenP EXPECT_EQ(multiGraphicsAllocation.getAllocationType(), svmObjectArg.getAllocationType()); EXPECT_EQ(&multiGraphicsAllocation, svmObjectArg.getMultiDeviceSvmAlloc()); } + +TEST(SvmObjectArgTest, givenNullPtrAllocationWhenGettingGraphicsAllocationFromSvmObjectArgThenNullptrIsReturned) { + { + GraphicsAllocation *nullGraphicsAllocation = nullptr; + SvmObjectArg svmObjectArg(nullGraphicsAllocation); + + EXPECT_EQ(nullptr, svmObjectArg.getGraphicsAllocation(0u)); + } + { + MultiGraphicsAllocation *nullMultiGraphicsAllocation = nullptr; + SvmObjectArg svmObjectArg(nullMultiGraphicsAllocation); + + EXPECT_EQ(nullptr, svmObjectArg.getGraphicsAllocation(0u)); + } +}