Skip to content

Commit 499af4c

Browse files
MithicSpiritafayaz-feral
authored andcommitted
Prevent platform profile error on unsupported systems
If a system does not support setting the platform profile (i.e., does not have the file /sys/firmware/acpi/platform_profile), then everything that interacts with it is skipped to prevent errors. This situation is more common than I expected.[1] [1] #524
1 parent 5f691c3 commit 499af4c

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

common/common-profile.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
3939
*/
4040
const char *profile_path = "/sys/firmware/acpi/platform_profile";
4141

42+
/**
43+
* Check if platform profile file exists
44+
*/
45+
int profile_exists(void)
46+
{
47+
return !access(profile_path, F_OK);
48+
}
49+
4250
/**
4351
* Return the current platform profile state
4452
*/

common/common-profile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ POSSIBILITY OF SUCH DAMAGE.
3232
#pragma once
3333

3434
#include <linux/limits.h>
35+
#include <unistd.h>
3536

3637
/**
3738
* Path for platform profile
3839
*/
3940
extern const char *profile_path;
4041

42+
/**
43+
* Check if platform profile file exists
44+
*/
45+
int profile_exists(void);
46+
4147
/**
4248
* Get the current platform profile state
4349
*/

daemon/gamemode-context.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int game_mode_set_governor(GameModeContext *self, enum GameModeGovernor g
317317

318318
static void game_mode_store_profile(GameModeContext *self)
319319
{
320-
if (self->current_profile != GAME_MODE_PROFILE_DEFAULT)
320+
if (!profile_exists() || self->current_profile != GAME_MODE_PROFILE_DEFAULT)
321321
return;
322322

323323
const char *initial_state = get_profile_state();
@@ -335,6 +335,11 @@ static int game_mode_set_profile(GameModeContext *self, enum GameModeProfile pro
335335
return 0;
336336
}
337337

338+
if (!profile_exists()) {
339+
LOG_MSG("Setting platform profile unsupported; skipping\n");
340+
return 0;
341+
}
342+
338343
const char *prof_str = NULL;
339344
char prof_config_str[CONFIG_VALUE_MAX] = { 0 };
340345
switch (prof) {

daemon/gamemode-tests.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ static int run_cpu_governor_tests(struct GameModeConfig *config)
361361
/* Check the platform profile setting works */
362362
static int run_platform_profile_tests(struct GameModeConfig *config)
363363
{
364+
if (!profile_exists())
365+
return 1;
366+
364367
/* get the two config parameters we care about */
365368
char desiredprof[CONFIG_VALUE_MAX] = { 0 };
366369
config_get_desired_profile(config, desiredprof);
@@ -866,15 +869,17 @@ static int game_mode_run_feature_tests(struct GameModeConfig *config)
866869
{
867870
LOG_MSG("::: Verifying platform profile setting\n");
868871

869-
int govstatus = run_platform_profile_tests(config);
872+
int profstatus = run_platform_profile_tests(config);
870873

871-
if (govstatus == 0)
874+
if (profstatus == 1)
875+
LOG_MSG("::: Passed (platform profile not supported)\n");
876+
else if (profstatus == 0)
872877
LOG_MSG("::: Passed\n");
873878
else {
874879
LOG_MSG("::: Failed!\n");
875880
LOG_MSG(" -- You may need to add your user to the gamemode group:");
876881
LOG_MSG(" -- $ sudo usermod -aG gamemode $(whoami)");
877-
// Consider the platform profile feature requried
882+
// If available, setting the platform profile should work
878883
status = -1;
879884
}
880885
}

0 commit comments

Comments
 (0)