Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent platform profile error on unsupported systems #526

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/common-profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ POSSIBILITY OF SUCH DAMAGE.
*/
const char *profile_path = "/sys/firmware/acpi/platform_profile";

/**
* Check if platform profile file exists
*/
int profile_exists(void)
{
return !access(profile_path, F_OK);
}

/**
* Return the current platform profile state
*/
Expand Down
6 changes: 6 additions & 0 deletions common/common-profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <linux/limits.h>
#include <unistd.h>

/**
* Path for platform profile
*/
extern const char *profile_path;

/**
* Check if platform profile file exists
*/
int profile_exists(void);

/**
* Get the current platform profile state
*/
Expand Down
7 changes: 6 additions & 1 deletion daemon/gamemode-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static int game_mode_set_governor(GameModeContext *self, enum GameModeGovernor g

static void game_mode_store_profile(GameModeContext *self)
{
if (self->current_profile != GAME_MODE_PROFILE_DEFAULT)
if (!profile_exists() || self->current_profile != GAME_MODE_PROFILE_DEFAULT)
return;

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

if (!profile_exists()) {
LOG_MSG("Setting platform profile unsupported; skipping");
return 0;
}

const char *prof_str = NULL;
char prof_config_str[CONFIG_VALUE_MAX] = { 0 };
switch (prof) {
Expand Down
9 changes: 7 additions & 2 deletions daemon/gamemode-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ static int run_cpu_governor_tests(struct GameModeConfig *config)
/* Check the platform profile setting works */
static int run_platform_profile_tests(struct GameModeConfig *config)
{
if (!profile_exists())
return 1;

/* get the two config parameters we care about */
char desiredprof[CONFIG_VALUE_MAX] = { 0 };
config_get_desired_profile(config, desiredprof);
Expand Down Expand Up @@ -866,9 +869,11 @@ static int game_mode_run_feature_tests(struct GameModeConfig *config)
{
LOG_MSG("::: Verifying platform profile setting\n");

int govstatus = run_platform_profile_tests(config);
int profstatus = run_platform_profile_tests(config);

if (govstatus == 0)
if (profstatus == 1)
LOG_MSG("::: Passed (platform profile not supported)\n");
else if (profstatus == 0)
LOG_MSG("::: Passed\n");
else {
LOG_MSG("::: Failed!\n");
Expand Down