diff options
author | Brice Videau <bvideau@anl.gov> | 2021-12-14 23:56:46 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-14 21:56:46 -0800 |
commit | d08d0e6452c15502c6eb7330eebb2f1264b958e8 (patch) | |
tree | bdf5ba8102c6bae066e1ce0a7756a6d4c7d63257 | |
parent | 3756f5f89fe20eadb5dd072970e748d0f944ae6f (diff) | |
download | OpenCL-ICD-Loader-d08d0e6452c15502c6eb7330eebb2f1264b958e8.tar.gz OpenCL-ICD-Loader-d08d0e6452c15502c6eb7330eebb2f1264b958e8.tar.bz2 OpenCL-ICD-Loader-d08d0e6452c15502c6eb7330eebb2f1264b958e8.zip |
Pedantic (#159)
* Replace usage of `d_type` of `struct dirent` by `stat()`.
* Remove unsigned comparison warning.
* Remove warning conversion for function pointers.
* Fix missing initializers.
* Remove unused variable warnings.
* Update loader/linux/icd_linux.c
Co-authored-by: Ronan Keryell <ronan@keryell.fr>
Co-authored-by: Ronan Keryell <ronan@keryell.fr>
-rw-r--r-- | loader/linux/icd_linux.c | 125 | ||||
-rw-r--r-- | test/driver_stub/cl.c | 3 | ||||
-rw-r--r-- | test/driver_stub/cl_ext.c | 2 | ||||
-rw-r--r-- | test/driver_stub/icd.c | 2 | ||||
-rw-r--r-- | test/loader_test/main.c | 2 | ||||
-rw-r--r-- | test/loader_test/param_struct.h | 3 | ||||
-rw-r--r-- | test/loader_test/test_buffer_object.c | 1 | ||||
-rw-r--r-- | test/loader_test/test_cl_runtime.c | 1 | ||||
-rw-r--r-- | test/loader_test/test_clgl.c | 6 | ||||
-rw-r--r-- | test/loader_test/test_create_calls.c | 9 | ||||
-rw-r--r-- | test/loader_test/test_image_objects.c | 2 | ||||
-rw-r--r-- | test/loader_test/test_kernel.c | 8 | ||||
-rw-r--r-- | test/loader_test/test_platforms.c | 2 | ||||
-rw-r--r-- | test/loader_test/test_program_objects.c | 2 | ||||
-rw-r--r-- | test/loader_test/test_sampler_objects.c | 1 |
15 files changed, 98 insertions, 71 deletions
diff --git a/loader/linux/icd_linux.c b/loader/linux/icd_linux.c index 1832614..7fa7bcd 100644 --- a/loader/linux/icd_linux.c +++ b/loader/linux/icd_linux.c @@ -24,6 +24,7 @@ #include <string.h> #include <stdlib.h> #include <sys/types.h> +#include <sys/stat.h> #include <dirent.h> #include <pthread.h> @@ -61,76 +62,74 @@ void khrIcdOsVendorsEnumerate(void) // attempt to load all files in the directory for (dirEntry = readdir(dir); dirEntry; dirEntry = readdir(dir) ) { - switch(dirEntry->d_type) + struct stat statBuff; + stat(dirEntry->d_name, &statBuff); + if (S_ISREG(statBuff.st_mode) || S_ISLNK(statBuff.st_mode)) { - case DT_UNKNOWN: - case DT_REG: - case DT_LNK: + const char* extension = ".icd"; + FILE *fin = NULL; + char* fileName = NULL; + char* buffer = NULL; + long bufferSize = 0; + + // make sure the file name ends in .icd + if (strlen(extension) > strlen(dirEntry->d_name) ) { - const char* extension = ".icd"; - FILE *fin = NULL; - char* fileName = NULL; - char* buffer = NULL; - long bufferSize = 0; - - // make sure the file name ends in .icd - if (strlen(extension) > strlen(dirEntry->d_name) ) - { - break; - } - if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) ) - { - break; - } - - // allocate space for the full path of the vendor library name - fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 2); - if (!fileName) - { - KHR_ICD_TRACE("Failed allocate space for ICD file path\n"); - break; - } - sprintf(fileName, "%s/%s", vendorPath, dirEntry->d_name); - - // open the file and read its contents - fin = fopen(fileName, "r"); - if (!fin) - { - free(fileName); - break; - } - fseek(fin, 0, SEEK_END); - bufferSize = ftell(fin); - - buffer = malloc(bufferSize+1); - if (!buffer) - { - free(fileName); - fclose(fin); - break; - } - memset(buffer, 0, bufferSize+1); - fseek(fin, 0, SEEK_SET); - if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) ) - { - free(fileName); - free(buffer); - fclose(fin); - break; - } - // ignore a newline at the end of the file - if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0'; - - // load the string read from the file - khrIcdVendorAdd(buffer); + continue; + } + if (strcmp(dirEntry->d_name + strlen(dirEntry->d_name) - strlen(extension), extension) ) + { + continue; + } + + // allocate space for the full path of the vendor library name + fileName = malloc(strlen(dirEntry->d_name) + strlen(vendorPath) + 2); + if (!fileName) + { + KHR_ICD_TRACE("Failed allocate space for ICD file path\n"); + continue; + } + sprintf(fileName, "%s/%s", vendorPath, dirEntry->d_name); + // open the file and read its contents + fin = fopen(fileName, "r"); + if (!fin) + { + free(fileName); + continue; + } + fseek(fin, 0, SEEK_END); + bufferSize = ftell(fin); + + buffer = malloc(bufferSize+1); + if (!buffer) + { + free(fileName); + fclose(fin); + continue; + } + memset(buffer, 0, bufferSize+1); + fseek(fin, 0, SEEK_SET); + if (bufferSize != (long)fread(buffer, 1, bufferSize, fin) ) + { free(fileName); free(buffer); fclose(fin); + continue; } - break; - default: - break; + // ignore a newline at the end of the file + if (buffer[bufferSize-1] == '\n') buffer[bufferSize-1] = '\0'; + + // load the string read from the file + khrIcdVendorAdd(buffer); + + free(fileName); + free(buffer); + fclose(fin); + } + else + { + continue; } } diff --git a/test/driver_stub/cl.c b/test/driver_stub/cl.c index 2325cd1..9b78e58 100644 --- a/test/driver_stub/cl.c +++ b/test/driver_stub/cl.c @@ -171,7 +171,7 @@ clGetDeviceIDs(cl_platform_id platform, { cl_int ret = CL_SUCCESS; - if ((num_entries > 1 || num_entries < 0) && devices != NULL) { + if ((num_entries > 1) && devices != NULL) { ret = CL_INVALID_VALUE; goto done; } @@ -902,6 +902,7 @@ clCompileProgram(cl_program program , void (CL_CALLBACK * pfn_notify)(cl_program program , void * user_data), void * user_data) CL_API_SUFFIX__VERSION_1_2 { + (void)input_headers; cl_int return_value = CL_OUT_OF_RESOURCES; test_icd_stub_log("clCompileProgram(%p, %u, %p, %p, %u, %p, %p, %p)\n", program, diff --git a/test/driver_stub/cl_ext.c b/test/driver_stub/cl_ext.c index ece0c59..4a5c38b 100644 --- a/test/driver_stub/cl_ext.c +++ b/test/driver_stub/cl_ext.c @@ -10,7 +10,7 @@ struct driverStubextFunc_st void *func; }; -#define EXT_FUNC(name) { #name, (void*)(name) } +#define EXT_FUNC(name) { #name, (void*)(intptr_t)(name) } static struct driverStubextFunc_st clExtensions[] = { diff --git a/test/driver_stub/icd.c b/test/driver_stub/icd.c index 75eb245..3f12d77 100644 --- a/test/driver_stub/icd.c +++ b/test/driver_stub/icd.c @@ -29,7 +29,7 @@ clSetCommandQueueProperty(cl_command_queue /* command_queue */, #define ICD_DISPATCH_TABLE_ENTRY(fn) \ assert(dispatchTable->entryCount < 256); \ - dispatchTable->entries[dispatchTable->entryCount++] = (void*)(fn) + dispatchTable->entries[dispatchTable->entryCount++] = (void*)(intptr_t)(fn) cl_int cliIcdDispatchTableCreate(CLIicdDispatchTable **outDispatchTable) { diff --git a/test/loader_test/main.c b/test/loader_test/main.c index 1d783d1..b8b7304 100644 --- a/test/loader_test/main.c +++ b/test/loader_test/main.c @@ -18,6 +18,8 @@ extern int test_icd_match(); int main(int argc, char **argv) { + (void)argc; + (void)argv; test_icd_initialize_app_log(); test_icd_initialize_stub_log(); diff --git a/test/loader_test/param_struct.h b/test/loader_test/param_struct.h index 9677d7d..00d96a9 100644 --- a/test/loader_test/param_struct.h +++ b/test/loader_test/param_struct.h @@ -802,7 +802,8 @@ struct clEnqueueMigrateMemObjects_st struct clEnqueueNDRangeKernel_st { cl_command_queue command_queue; - cl_kernel kernel; cl_uint work_dim; + cl_kernel kernel; + cl_uint work_dim; const size_t *global_work_offset; const size_t *global_work_size; const size_t *local_work_size; diff --git a/test/loader_test/test_buffer_object.c b/test/loader_test/test_buffer_object.c index 1710e88..90ff0d1 100644 --- a/test/loader_test/test_buffer_object.c +++ b/test/loader_test/test_buffer_object.c @@ -336,6 +336,7 @@ int test_clEnqueueMapBuffer(const struct clEnqueueMapBuffer_st *data) int test_clRetainMemObject(const struct clRetainMemObject_st *data) { + (void)data; test_icd_app_log("clRetainMemObject(%p)\n", buffer); ret_val=clRetainMemObject(buffer); diff --git a/test/loader_test/test_cl_runtime.c b/test/loader_test/test_cl_runtime.c index 60bd3ee..380627d 100644 --- a/test/loader_test/test_cl_runtime.c +++ b/test/loader_test/test_cl_runtime.c @@ -14,6 +14,7 @@ const struct clGetCommandQueueInfo_st clGetCommandQueueInfoData[NUM_ITEMS_clGetC int test_clRetainCommandQueue(const struct clRetainCommandQueue_st *data) { + (void)data; cl_int ret_val; test_icd_app_log("clRetainCommandQueue(%p)\n", command_queue); diff --git a/test/loader_test/test_clgl.c b/test/loader_test/test_clgl.c index ee84e3c..088b7d6 100644 --- a/test/loader_test/test_clgl.c +++ b/test/loader_test/test_clgl.c @@ -268,7 +268,8 @@ int test_clCreateEventFromGLsyncKHR(const struct clCreateEventFromGLsyncKHR_st* data->sync, data->errcode_ret); - pfn_clCreateEventFromGLsyncKHR = clGetExtensionFunctionAddress("clCreateEventFromGLsyncKHR"); + pfn_clCreateEventFromGLsyncKHR = (PFN_clCreateEventFromGLsyncKHR) + (intptr_t)clGetExtensionFunctionAddress("clCreateEventFromGLsyncKHR"); if (!pfn_clCreateEventFromGLsyncKHR) { test_icd_app_log("clGetExtensionFunctionAddress failed!\n"); return 1; @@ -305,7 +306,8 @@ int test_clGetGLContextInfoKHR(const struct clGetGLContextInfoKHR_st* data) data->param_value, data->param_value_size_ret); - pfn_clGetGLContextInfoKHR = clGetExtensionFunctionAddress("clGetGLContextInfoKHR"); + pfn_clGetGLContextInfoKHR = (PFN_clGetGLContextInfoKHR) + (intptr_t)clGetExtensionFunctionAddress("clGetGLContextInfoKHR"); if (!pfn_clGetGLContextInfoKHR) { test_icd_app_log("clGetExtensionFunctionAddress failed!\n"); return 1; diff --git a/test/loader_test/test_create_calls.c b/test/loader_test/test_create_calls.c index 9bd3514..4cdcfd7 100644 --- a/test/loader_test/test_create_calls.c +++ b/test/loader_test/test_create_calls.c @@ -157,6 +157,8 @@ int test_clGetPlatformIDs(const struct clGetPlatformIDs_st* data) data->num_entries, &platforms, &num_platforms); +#else + (void)data; #endif ret_val = clGetPlatformIDs(0, @@ -614,6 +616,7 @@ const struct clReleaseSampler_st clReleaseSamplerData[NUM_ITEMS_clReleaseSampler int test_clReleaseSampler(const struct clReleaseSampler_st *data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseSampler(%p)\n", sampler); @@ -646,6 +649,7 @@ const struct clReleaseEvent_st clReleaseEventData[NUM_ITEMS_clReleaseEvent] = int test_clReleaseEvent(const struct clReleaseEvent_st* data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseEvent(%p)\n", event); @@ -665,6 +669,7 @@ const struct clReleaseKernel_st clReleaseKernelData[NUM_ITEMS_clReleaseKernel] = int test_clReleaseKernel(const struct clReleaseKernel_st* data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseKernel(%p)\n", kernel); @@ -684,6 +689,7 @@ const struct clReleaseProgram_st clReleaseProgramData[NUM_ITEMS_clReleaseProgram int test_clReleaseProgram(const struct clReleaseProgram_st *data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseProgram(%p)\n", program); @@ -703,6 +709,7 @@ const struct clReleaseCommandQueue_st clReleaseCommandQueueData[NUM_ITEMS_clRele int test_clReleaseCommandQueue(const struct clReleaseCommandQueue_st *data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseCommandQueue(%p)\n", command_queue); @@ -722,6 +729,7 @@ const struct clReleaseContext_st clReleaseContextData[NUM_ITEMS_clReleaseContext int test_clReleaseContext(const struct clReleaseContext_st* data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseContext(%p)\n", context); @@ -741,6 +749,7 @@ const struct clReleaseDevice_st clReleaseDeviceData[NUM_ITEMS_clReleaseDevice] = int test_clReleaseDevice(const struct clReleaseDevice_st* data) { + (void)data; int ret_val = CL_OUT_OF_RESOURCES; test_icd_app_log("clReleaseDevice(%p)\n", devices); diff --git a/test/loader_test/test_image_objects.c b/test/loader_test/test_image_objects.c index 34040ce..c6b99e7 100644 --- a/test/loader_test/test_image_objects.c +++ b/test/loader_test/test_image_objects.c @@ -27,7 +27,7 @@ const struct clEnqueueCopyBufferToImage_st clEnqueueCopyBufferToImageData[NUM_IT const struct clEnqueueMapImage_st clEnqueueMapImageData[NUM_ITEMS_clEnqueueMapImage] = { - { NULL, NULL, 0, 0x0, NULL, NULL, NULL, NULL,0, NULL, NULL} + { NULL, NULL, 0, 0x0, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL} }; const struct clEnqueueReadImage_st clEnqueueReadImageData[NUM_ITEMS_clEnqueueReadImage] = diff --git a/test/loader_test/test_kernel.c b/test/loader_test/test_kernel.c index be116ed..2382eab 100644 --- a/test/loader_test/test_kernel.c +++ b/test/loader_test/test_kernel.c @@ -26,6 +26,7 @@ struct clRetainKernel_st clRetainKernelData[NUM_ITEMS_clRetainKernel] = int test_clRetainKernel(const struct clRetainKernel_st* data) { + (void)data; test_icd_app_log("clRetainKernel(%p)\n", kernel); ret_val=clRetainKernel(kernel); @@ -168,7 +169,7 @@ int test_clEnqueueMigrateMemObjects(const struct clEnqueueMigrateMemObjects_st* struct clEnqueueNDRangeKernel_st clEnqueueNDRangeKernelData[NUM_ITEMS_clEnqueueNDRangeKernel] = { - {NULL, NULL, 0, NULL, NULL, NULL, 0, NULL} + {NULL, NULL, 0, NULL, NULL, NULL, 0, NULL, NULL} }; int test_clEnqueueNDRangeKernel(const struct clEnqueueNDRangeKernel_st* data) @@ -345,6 +346,7 @@ struct clRetainEvent_st clRetainEventData[NUM_ITEMS_clRetainEvent] = int test_clRetainEvent(const struct clRetainEvent_st* data) { + (void)data; test_icd_app_log("clRetainEvent(%p)\n", event); ret_val=clRetainEvent(event); @@ -361,6 +363,7 @@ struct clEnqueueMarker_st clEnqueueMarkerData[NUM_ITEMS_clEnqueueMarker] = int test_clEnqueueMarker(const struct clEnqueueMarker_st* data) { + (void)data; test_icd_app_log("clEnqueueMarker(%p, %p)\n", command_queue, &event); ret_val = clEnqueueMarker(command_queue, &event); @@ -443,6 +446,7 @@ struct clEnqueueBarrier_st clEnqueueBarrierData[NUM_ITEMS_clEnqueueBarrier] = int test_clEnqueueBarrier(const struct clEnqueueBarrier_st* data) { + (void)data; test_icd_app_log("clEnqueueBarrier(%p)\n", command_queue); ret_val = clEnqueueBarrier(command_queue); @@ -483,6 +487,7 @@ struct clFlush_st clFlushData[NUM_ITEMS_clFlush] = int test_clFlush(const struct clFlush_st* data) { + (void)data; test_icd_app_log("clFlush(%p)\n", command_queue); ret_val=clFlush(command_queue); @@ -499,6 +504,7 @@ struct clFinish_st clFinishData[NUM_ITEMS_clFinish] = int test_clFinish(const struct clFinish_st* data) { + (void)data; test_icd_app_log("clFinish(%p)\n", command_queue); ret_val=clFinish(command_queue); diff --git a/test/loader_test/test_platforms.c b/test/loader_test/test_platforms.c index cb2839b..5700738 100644 --- a/test/loader_test/test_platforms.c +++ b/test/loader_test/test_platforms.c @@ -49,6 +49,7 @@ struct clRetainDevice_st clRetainDeviceData[NUM_ITEMS_clRetainDevice] = int test_clRetainContext(const struct clRetainContext_st* data) { + (void)data; cl_int ret_val; test_icd_app_log("clRetainContext(%p)\n", context); @@ -176,6 +177,7 @@ int test_clCreateSubDevices(const struct clCreateSubDevices_st* data) int test_clRetainDevice(const struct clRetainDevice_st* data) { + (void)data; cl_int ret_val; test_icd_app_log("clRetainDevice(%p)\n", devices); diff --git a/test/loader_test/test_program_objects.c b/test/loader_test/test_program_objects.c index 04395d4..8e64372 100644 --- a/test/loader_test/test_program_objects.c +++ b/test/loader_test/test_program_objects.c @@ -51,6 +51,7 @@ const struct clGetProgramBuildInfo_st clGetProgramBuildInfoData[NUM_ITEMS_clGetP int test_clRetainProgram(const struct clRetainProgram_st *data) { + (void)data; cl_int ret_val; test_icd_app_log("clRetainProgram(%p)\n", @@ -152,6 +153,7 @@ int test_clLinkProgram(const struct clLinkProgram_st *data) int test_clUnloadPlatformCompiler(const struct clUnloadPlatformCompiler_st *data) { + (void)data; cl_int ret_val; test_icd_app_log("clUnloadPlatformCompiler(%p)\n", platform); diff --git a/test/loader_test/test_sampler_objects.c b/test/loader_test/test_sampler_objects.c index 7994411..afc11be 100644 --- a/test/loader_test/test_sampler_objects.c +++ b/test/loader_test/test_sampler_objects.c @@ -17,6 +17,7 @@ const struct clGetSamplerInfo_st clGetSamplerInfoData[NUM_ITEMS_clGetSamplerInfo int test_clRetainSampler(const struct clRetainSampler_st *data) { + (void)data; cl_int ret_val; test_icd_app_log("clRetainSampler(%p)\n", sampler); |