From fe9b5c8744f40a46d51adb4b3d04a260fe06c802 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Thu, 31 Jan 2019 18:25:46 +0000 Subject: [PATCH] Error with invalid device or vendor values --- daemon/daemon_config.c | 2 +- daemon/gamemode-gpu.c | 24 ++++++++++++++++++++++-- daemon/gpu-query.h | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/daemon/daemon_config.c b/daemon/daemon_config.c index f342254..6af386b 100644 --- a/daemon/daemon_config.c +++ b/daemon/daemon_config.c @@ -261,7 +261,7 @@ static void load_config_files(GameModeConfig *self) self->inhibit_screensaver = 1; /* Defaults to on */ self->apply_gpu_optimisations = 0; self->gpu_vendor = 0; - self->gpu_device = 0; + self->gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */ self->nv_core_clock_mhz_offset = 0; self->nv_mem_clock_mhz_offset = 0; self->amd_core_clock_percentage = 0; diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index d37e941..01aa519 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -68,12 +68,31 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) GameModeGPUInfo *new_info = malloc(sizeof(GameModeGPUInfo)); memset(new_info, 0, sizeof(GameModeGPUInfo)); - // TODO: Fill in the GPU vendor and device automatically - /* Get the config parameters */ config_get_gpu_vendor(config, &new_info->vendor); config_get_gpu_device(config, &new_info->device); + /* TODO: Detect the GPU vendor and device automatically when these aren't set */ + + /* verify device ID */ + if (new_info->device == -1) { + LOG_ERROR("Invalid gpu_device value set in configuration, will not appli optimisations!\n"); + free(new_info); + return -1; + } + + /* verify GPU vendor */ + if (new_info->vendor != Vendor_NVIDIA && new_info->vendor != Vendor_AMD && + new_info->vendor != Vendor_Intel) { + LOG_ERROR("Invalid gpu_vendor value set in configuration, will not apply optimisations!\n"); + LOG_ERROR("Possible values are: 0x%04x (NVIDIA) 0x%04x (AMD) 0x%04x (Intel)\n", + Vendor_NVIDIA, + Vendor_AMD, + Vendor_Intel); + free(new_info); + return -1; + } + /* Load the config based on GPU */ switch (new_info->vendor) { case Vendor_NVIDIA: @@ -87,6 +106,7 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info) default: break; } + /* TODO : Sanity check these values */ /* Give back the new gpu info */ *info = new_info; diff --git a/daemon/gpu-query.h b/daemon/gpu-query.h index 5c3eebc..4116888 100644 --- a/daemon/gpu-query.h +++ b/daemon/gpu-query.h @@ -41,8 +41,8 @@ enum GPUVendor { /* Storage for GPU info*/ struct GameModeGPUInfo { - enum GPUVendor vendor; - int device; /* path to device, ie. /sys/class/drm/card#/ */ + long vendor; + long device; /* path to device, ie. /sys/class/drm/card#/ */ long core; /* Core clock to apply */ long mem; /* Mem clock to apply */