SWDEV-259210 : Handle invalid inputs for hipDeviceGetByPCIBusId and hipDeviceGetPCIBusId APIs
Change-Id: Iab48604941c4c715ee3357ace2e2d26dbc8cad33
This commit is contained in:
committed by
Anusha Godavarthy Surya
orang tua
4b3c04c3b0
melakukan
ef415ec610
@@ -332,7 +332,7 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
|
||||
int pciBusID = -1;
|
||||
int pciDeviceID = -1;
|
||||
int pciDomainID = -1;
|
||||
|
||||
bool found = false;
|
||||
if (sscanf (pciBusIdstr, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID) == 0x3) {
|
||||
int count = 0;
|
||||
ihipDeviceGetCount(&count);
|
||||
@@ -345,10 +345,14 @@ hipError_t hipDeviceGetByPCIBusId(int* device, const char*pciBusIdstr) {
|
||||
if ((pciBusID == prop.pciBusID) && (pciDomainID == prop.pciDomainID)
|
||||
&& (pciDeviceID == prop.pciDeviceID)) {
|
||||
*device = i;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
@@ -389,11 +393,11 @@ hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) {
|
||||
|
||||
int count;
|
||||
ihipDeviceGetCount(&count);
|
||||
if (device < 0 || device > count) {
|
||||
if (device < 0 || device >= count) {
|
||||
HIP_RETURN(hipErrorInvalidDevice);
|
||||
}
|
||||
|
||||
if (pciBusId == nullptr || len < 0) {
|
||||
if (pciBusId == nullptr || len <= 0) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user