From 702407595a998d676113bc895fd0930736e93535 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sat, 1 Jun 2019 11:12:10 +0100 Subject: [PATCH] Rename duplicate CONFIG_VALUE_MAX Leave a static assert to ensure they're in sync when relevant in gamemode-gpu --- common/common-gpu.h | 4 ++-- daemon/gamemode-gpu.c | 2 ++ util/gpuclockctl.c | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/common-gpu.h b/common/common-gpu.h index 59749c0..83f3c12 100644 --- a/common/common-gpu.h +++ b/common/common-gpu.h @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #pragma once -#define CONFIG_VALUE_MAX 256 +#define GPU_VALUE_MAX 256 /* Enums for GPU vendors */ enum GPUVendor { @@ -52,7 +52,7 @@ struct GameModeGPUInfo { long nv_mem; /* Nvidia mem clock */ long nv_powermizer_mode; /* NV Powermizer Mode */ - char amd_performance_level[CONFIG_VALUE_MAX]; /* The AMD performance level set to */ + char amd_performance_level[GPU_VALUE_MAX]; /* The AMD performance level set to */ }; /* Get the vendor for a device */ diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 2ba977c..32fad3d 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -42,6 +42,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "build-config.h" +_Static_assert(CONFIG_VALUE_MAX == GPU_VALUE_MAX, "Config max value and GPU value out of sync!"); + /** * Attempts to identify the current in use GPU information */ diff --git a/util/gpuclockctl.c b/util/gpuclockctl.c index 438cc76..0e8398b 100644 --- a/util/gpuclockctl.c +++ b/util/gpuclockctl.c @@ -304,8 +304,8 @@ static int get_gpu_state_amd(struct GameModeGPUInfo *info) int ret = 0; - char buff[CONFIG_VALUE_MAX] = { 0 }; - if (!fgets(buff, CONFIG_VALUE_MAX, file)) { + char buff[GPU_VALUE_MAX] = { 0 }; + if (!fgets(buff, GPU_VALUE_MAX, file)) { LOG_ERROR("Could not read file %s (%s)!\n", path, strerror(errno)); ret = -1; } @@ -317,8 +317,8 @@ static int get_gpu_state_amd(struct GameModeGPUInfo *info) if (ret == 0) { /* Copy in the value from the file */ - strncpy(info->amd_performance_level, buff, CONFIG_VALUE_MAX - 1); - info->amd_performance_level[CONFIG_VALUE_MAX - 1] = '\0'; + strncpy(info->amd_performance_level, buff, GPU_VALUE_MAX - 1); + info->amd_performance_level[GPU_VALUE_MAX - 1] = '\0'; } return ret; @@ -468,7 +468,7 @@ int main(int argc, char *argv[]) LOG_ERROR("Must pass performance level for AMD gpu!\n"); print_usage_and_exit(); } - strncpy(info.amd_performance_level, argv[3], CONFIG_VALUE_MAX - 1); + strncpy(info.amd_performance_level, argv[3], GPU_VALUE_MAX - 1); return set_gpu_state_amd(&info); break; default: