Browse Source

Rename duplicate CONFIG_VALUE_MAX

	Leave a static assert to ensure they're in sync when relevant in gamemode-gpu
Marc Di Luzio 5 years ago
parent
commit
702407595a
3 changed files with 9 additions and 7 deletions
  1. 2 2
      common/common-gpu.h
  2. 2 0
      daemon/gamemode-gpu.c
  3. 5 5
      util/gpuclockctl.c

+ 2 - 2
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 */

+ 2 - 0
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
  */

+ 5 - 5
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: