Skip to content

Commit 77320c3

Browse files
authored
Merge pull request #1844 from tkatila/levelzero-add-calloc-check
levelzero: add missing calloc return value check
2 parents 9bd3975 + b4a3ccd commit 77320c3

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cmd/gpu_levelzero/ze.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <stdbool.h>
1919

2020
#define VENDOR_ID_INTEL 0x8086
21+
#define TEMP_ERROR_RET_VAL -999.0
2122

2223
void zes_set_verbosity(const int level);
2324

cmd/gpu_levelzero/zes.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ static ze_result_t enumerate_zes_devices(void)
113113
}
114114

115115
zes_handles = calloc(count, sizeof(zes_device_handle_t));
116+
if (zes_handles == NULL) {
117+
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
118+
}
116119

117120
res = zesDeviceGet(handle, &count, zes_handles);
118121
if (res != ZE_RESULT_SUCCESS) {
@@ -355,7 +358,7 @@ bool zes_device_bus_is_healthy(char* bdf_address, uint32_t* error)
355358
double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
356359
{
357360
if (getenv("UNITTEST") != NULL) {
358-
return -999.0;
361+
return TEMP_ERROR_RET_VAL;
359362
}
360363

361364
uint32_t requestedType = 0;
@@ -368,7 +371,7 @@ double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
368371
} else {
369372
*error = ZE_RESULT_ERROR_INVALID_ARGUMENT;
370373

371-
return -999.0;
374+
return TEMP_ERROR_RET_VAL;
372375
}
373376

374377
print_log(LOG_DEBUG, "Fetch %s temperature for %s\n", sensor, bdf_address);
@@ -378,31 +381,31 @@ double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
378381
if (res != ZE_RESULT_SUCCESS) {
379382
*error = res;
380383

381-
return -999.0;
384+
return TEMP_ERROR_RET_VAL;
382385
}
383386
}
384387

385388
zes_device_handle_t handle = retrieve_handle_for_bdf(bdf_address);
386389
if (handle == 0) {
387390
*error = ZE_RESULT_ERROR_UNKNOWN;
388391

389-
return -999.0;
392+
return TEMP_ERROR_RET_VAL;
390393
}
391394

392395
uint32_t count = 0;
393396
ze_result_t res = zesDeviceEnumTemperatureSensors(handle, &count, NULL);
394397
if (res != ZE_RESULT_SUCCESS || count == 0) {
395398
*error = res;
396399

397-
return -999.0;
400+
return TEMP_ERROR_RET_VAL;
398401
}
399402

400403
zes_temp_handle_t tempHandles[count];
401404
res = zesDeviceEnumTemperatureSensors(handle, &count, tempHandles);
402405
if (res != ZE_RESULT_SUCCESS) {
403406
*error = res;
404407

405-
return -999.0;
408+
return TEMP_ERROR_RET_VAL;
406409
}
407410

408411
for (uint32_t i = 0; i < count; ++i) {
@@ -412,7 +415,7 @@ double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
412415
if (res != ZE_RESULT_SUCCESS) {
413416
*error = res;
414417

415-
return -999.0;
418+
return TEMP_ERROR_RET_VAL;
416419
}
417420

418421
if (props.type != requestedType) {
@@ -424,7 +427,7 @@ double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
424427
if (res != ZE_RESULT_SUCCESS) {
425428
*error = res;
426429

427-
return -999.0;
430+
return TEMP_ERROR_RET_VAL;
428431
}
429432

430433
print_log(LOG_DEBUG, "> Temperature: %.1f\n", tempCelsius);
@@ -434,5 +437,5 @@ double zes_device_temp_max(char* bdf_address, char* sensor, uint32_t* error)
434437

435438
*error = ZE_RESULT_ERROR_NOT_AVAILABLE;
436439

437-
return -999.0;
440+
return TEMP_ERROR_RET_VAL;
438441
}

0 commit comments

Comments
 (0)