SWDEV-271126 - Memory obtained from getDeviceMEmory can be NULL

which can cause segmentation faults. Hence checking for its sanity

Signed-off-by: Ashutosh Mishra <ashutosh.mishra@amd.com>
Change-Id: I78b4d029f0926a1369a8ebbeb4aef951a8f1f1d7
This commit is contained in:
Ashutosh Mishra
2021-02-26 16:56:33 +05:30
committed by Ashutosh Mishra
parent c77caa3fbf
commit abff21c4fc
+9 -1
View File
@@ -2117,7 +2117,15 @@ hipError_t hipPointerGetAttributes(hipPointerAttribute_t* attributes, const void
attributes->hostPointer = static_cast<char*>(memObj->getSvmPtr()) + offset;
}
}
attributes->devicePointer = reinterpret_cast<char*>(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<char*>(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;