From d73446d49b0ff7b07450095f114c8fc2439f240a Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 23 Nov 2021 17:25:10 +0100 Subject: [PATCH] [PATCH 41/90] CUDA: const correctness in get/free device name string This silences a couple of const correctness warnings due to implicit casts to/from char*/const char*. Gbp-Pq: Name 0041-CUDA-const-correctness-in-get-free-device-name-strin.patch --- lib/CL/devices/cuda/pocl-cuda.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/CL/devices/cuda/pocl-cuda.c b/lib/CL/devices/cuda/pocl-cuda.c index 1d8d4ce..6638dcc 100644 --- a/lib/CL/devices/cuda/pocl-cuda.c +++ b/lib/CL/devices/cuda/pocl-cuda.c @@ -286,12 +286,15 @@ pocl_cuda_init (unsigned j, cl_device_id dev, const char *parameters) ret = CL_INVALID_DEVICE; /* Get specific device name */ - dev->long_name = dev->short_name = calloc (256, sizeof (char)); - - if (ret != CL_INVALID_DEVICE) - cuDeviceGetName (dev->long_name, 256, data->device); - else - snprintf (dev->long_name, 255, "Unavailable CUDA device #%d", j); + { + char *name = calloc (256, sizeof (char)); + + if (ret != CL_INVALID_DEVICE) + cuDeviceGetName (name, 256, data->device); + else + snprintf (name, 255, "Unavailable CUDA device #%d", j); + dev->long_name = dev->short_name = name; + } SETUP_DEVICE_CL_VERSION (CUDA_DEVICE_CL_VERSION_MAJOR, CUDA_DEVICE_CL_VERSION_MINOR); @@ -533,7 +536,10 @@ pocl_cuda_uninit (unsigned j, cl_device_id device) POCL_MEM_FREE (data); device->data = NULL; - POCL_MEM_FREE (device->long_name); + char *name = (char*)device->long_name; + POCL_MEM_FREE (name); + device->long_name = device->short_name = NULL; + return CL_SUCCESS; } -- 2.30.2