From 1a2ed0ec645d02eee4dcea6ffe94c312e43ba932 Mon Sep 17 00:00:00 2001 From: Yong Zhao Date: Tue, 15 Nov 2016 15:06:05 -0500 Subject: [PATCH] Making the code more robust by checking the NULL pointer Change-Id: I36b9f73eadd7547c71fe3641ac131c7408b14816 Signed-off-by: Yong Zhao [ROCm/ROCR-Runtime commit: a1f417715bb4aabc6c06f98769b9b986078b2f0c] --- projects/rocr-runtime/src/memory.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/projects/rocr-runtime/src/memory.c b/projects/rocr-runtime/src/memory.c index bb086d9d6d..8687977cec 100644 --- a/projects/rocr-runtime/src/memory.c +++ b/projects/rocr-runtime/src/memory.c @@ -183,6 +183,11 @@ hsaKmtFreeMemory( { CHECK_KFD_OPEN(); + if (MemoryAddress == NULL) { + fprintf(stderr, "FIXME: freeing NULL pointer\n"); + return HSAKMT_STATUS_ERROR; + } + fmm_release(MemoryAddress); return HSAKMT_STATUS_SUCCESS; } @@ -283,6 +288,11 @@ hsaKmtMapMemoryToGPU( { CHECK_KFD_OPEN(); + if (MemoryAddress == NULL) { + fprintf(stderr, "FIXME: mapping NULL pointer\n"); + return HSAKMT_STATUS_ERROR; + } + if (AlternateVAGPU) *AlternateVAGPU = 0; @@ -306,6 +316,11 @@ hsaKmtMapMemoryToGPUNodes( uint32_t *gpu_id_array; HSAKMT_STATUS ret; + if (MemoryAddress == NULL) { + fprintf(stderr, "FIXME: mapping NULL pointer\n"); + return HSAKMT_STATUS_ERROR; + } + if (!is_dgpu && NumberOfNodes == 1) return hsaKmtMapMemoryToGPU(MemoryAddress, MemorySizeInBytes,