From a6e72de83de0b02de8a5df3ddd753e080341b0bd Mon Sep 17 00:00:00 2001 From: Jaydeep Patel Date: Tue, 6 Jun 2023 04:34:23 +0000 Subject: [PATCH] SWDEV-403768 - Check mem type is managed and result mem addresses are not null. Change-Id: Ib40c468a981e0dd42b2da65aeb7543b11af4bc90 --- hipamd/src/hip_hmm.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hipamd/src/hip_hmm.cpp b/hipamd/src/hip_hmm.cpp index 76e61282ae..2bcb832a0d 100644 --- a/hipamd/src/hip_hmm.cpp +++ b/hipamd/src/hip_hmm.cpp @@ -196,6 +196,24 @@ hipError_t hipMemRangeGetAttributes(void** data, size_t* data_sizes, HIP_RETURN(hipErrorInvalidValue); } + if (*data_sizes > 0) { + for (int i = 0 ; i<*data_sizes ; i++) { + if (!data[i]) { + HIP_RETURN(hipErrorInvalidValue); + } + } + } + + size_t offset = 0; + amd::Memory* memObj = getMemoryObject(dev_ptr, offset); + if (memObj) { + if (!(memObj->getMemFlags() & (CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_ALLOC_HOST_PTR))) { + HIP_RETURN(hipErrorInvalidValue); + } + } else { + HIP_RETURN(hipErrorInvalidValue); + } + // Shouldn't matter for which device the interface is called amd::Device* dev = g_devices[0]->devices()[0]; // Get the allocation attributes from AMD HMM