From 0a76232c975044e2906a58a20104164e1b862844 Mon Sep 17 00:00:00 2001 From: Sourabh Betigeri Date: Thu, 10 Mar 2022 11:36:38 -0800 Subject: [PATCH] SWDEV-326791 - Fixes hipHostRegister's inconsistent behavior when invalid parameter is passed Change-Id: I5d5d979485cfd99908f84cc92648177cb8a569c7 --- hipamd/src/hip_memory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hipamd/src/hip_memory.cpp b/hipamd/src/hip_memory.cpp index 88456f4466..efacdd23b1 100644 --- a/hipamd/src/hip_memory.cpp +++ b/hipamd/src/hip_memory.cpp @@ -977,7 +977,9 @@ hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) { hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) { HIP_INIT_API(hipHostRegister, hostPtr, sizeBytes, flags); CHECK_STREAM_CAPTURE_SUPPORTED(); - if(hostPtr != nullptr) { + if (hostPtr == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } else { amd::Memory* mem = new (*hip::host_device->asContext()) amd::Buffer(*hip::host_device->asContext(), CL_MEM_USE_HOST_PTR | CL_MEM_SVM_ATOMICS, sizeBytes); @@ -1005,8 +1007,6 @@ hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) mem->getUserData().deviceId = hip::getCurrentDevice()->deviceId(); } HIP_RETURN(hipSuccess); - } else { - HIP_RETURN_DURATION(ihipMalloc(&hostPtr, sizeBytes, flags), hostPtr); } }