From abff21c4fc6d138eb7ea25cc589dc6101b1c2c86 Mon Sep 17 00:00:00 2001 From: Ashutosh Mishra Date: Fri, 26 Feb 2021 16:56:33 +0530 Subject: [PATCH] SWDEV-271126 - Memory obtained from getDeviceMEmory can be NULL which can cause segmentation faults. Hence checking for its sanity Signed-off-by: Ashutosh Mishra Change-Id: I78b4d029f0926a1369a8ebbeb4aef951a8f1f1d7 --- rocclr/hip_memory.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rocclr/hip_memory.cpp b/rocclr/hip_memory.cpp index ab3518e9b3..ef9c50e0aa 100755 --- a/rocclr/hip_memory.cpp +++ b/rocclr/hip_memory.cpp @@ -2117,7 +2117,15 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void attributes->hostPointer = static_cast(memObj->getSvmPtr()) + offset; } } - attributes->devicePointer = reinterpret_cast(memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0])->virtualAddress() + offset); + + device::Memory* devMem = memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]); + //getDeviceMemory can fail, hence validate the sanity of the mem obtained + if (nullptr == devMem) { + DevLogPrintfError("getDeviceMemory for ptr failed : %p \n", ptr); + HIP_RETURN(hipErrorMemoryAllocation); + } + + attributes->devicePointer = reinterpret_cast(devMem->virtualAddress() + offset); constexpr uint32_t kManagedAlloc = (CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_ALLOC_HOST_PTR); attributes->isManaged = ((memObj->getMemFlags() & kManagedAlloc) == kManagedAlloc) ? true : false;