From 0e4dbe0b2fd75a0c19a90a173134eeb2bd0f0c2a Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Tue, 13 Jun 2017 13:35:50 +0530 Subject: [PATCH] Input args NULL check in hipChooseDevice Change-Id: I1a7b8cded2f81d739645bbf3dab2f04bb9c3c796 [ROCm/hip commit: a833b9a704b780dce49870ae3e3e756904927beb] --- projects/hip/src/hip_device.cpp | 110 +++++++++++++++++--------------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/projects/hip/src/hip_device.cpp b/projects/hip/src/hip_device.cpp index 93c1c20484..05db4c2b30 100644 --- a/projects/hip/src/hip_device.cpp +++ b/projects/hip/src/hip_device.cpp @@ -415,72 +415,78 @@ hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop ) int inPropCount = 0; int matchedPropCount = 0; hipError_t e = hipSuccess; - ihipGetDeviceCount( &deviceCount ); - *device = 0; - for (int i = 0; i < deviceCount; i++) { - ihipGetDeviceProperties( &tempProp, i ); - if(prop->major != 0) { - inPropCount++; - if(tempProp.major >= prop->major) { - matchedPropCount++; - } - if(prop->minor != 0) { + if((device == NULL) || (prop == NULL)) { + e = hipErrorInvalidValue; + } + if(e == hipSuccess) { + ihipGetDeviceCount( &deviceCount ); + *device = 0; + for (int i = 0; i < deviceCount; i++) { + ihipGetDeviceProperties( &tempProp, i ); + if(prop->major != 0) { inPropCount++; - if(tempProp.minor >= prop->minor) { - matchedPropCount++; - } + if(tempProp.major >= prop->major) { + matchedPropCount++; + } + if(prop->minor != 0) { + inPropCount++; + if(tempProp.minor >= prop->minor) { + matchedPropCount++; + } + } } - } - if(prop->totalGlobalMem != 0) { - inPropCount++; - if(tempProp.totalGlobalMem >= prop->totalGlobalMem) { - matchedPropCount++; + if(prop->totalGlobalMem != 0) { + inPropCount++; + if(tempProp.totalGlobalMem >= prop->totalGlobalMem) { + matchedPropCount++; + } } - } - if(prop->sharedMemPerBlock != 0) { - inPropCount++; - if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) { - matchedPropCount++; + if(prop->sharedMemPerBlock != 0) { + inPropCount++; + if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) { + matchedPropCount++; + } } - } - if(prop->maxThreadsPerBlock != 0) { - inPropCount++; - if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) { - matchedPropCount++; + if(prop->maxThreadsPerBlock != 0) { + inPropCount++; + if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) { + matchedPropCount++; + } } - } - if(prop->totalConstMem != 0) { - inPropCount++; - if(tempProp.totalConstMem >= prop->totalConstMem ) { - matchedPropCount++; + if(prop->totalConstMem != 0) { + inPropCount++; + if(tempProp.totalConstMem >= prop->totalConstMem ) { + matchedPropCount++; + } } - } - if(prop->multiProcessorCount != 0) { - inPropCount++; - if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) { - matchedPropCount++; + if(prop->multiProcessorCount != 0) { + inPropCount++; + if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) { + matchedPropCount++; + } } - } - if(prop->maxThreadsPerMultiProcessor != 0) { - inPropCount++; - if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) { - matchedPropCount++; + if(prop->maxThreadsPerMultiProcessor != 0) { + inPropCount++; + if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) { + matchedPropCount++; + } } - } - if(prop->memoryClockRate != 0) { - inPropCount++; - if(tempProp.memoryClockRate >= prop->memoryClockRate ) { - matchedPropCount++; + if(prop->memoryClockRate != 0) { + inPropCount++; + if(tempProp.memoryClockRate >= prop->memoryClockRate ) { + matchedPropCount++; + } + } + if(inPropCount == matchedPropCount) { + *device = i; } - } - if(inPropCount == matchedPropCount) { - *device = i; - } #if 0 else{ e= hipErrorInvalidValue; } #endif + } } return ihipLogStatus(e); } +