Skip to content

Commit d38b457

Browse files
committed
platform/x86: acer-wmi: Fix initialization of last_non_turbo_profile
JIRA: https://issues.redhat.com/browse/RHEL-89362 commit 3ef4ea5 Author: Armin Wolf <W_Armin@gmx.de> Date: Sun Jan 19 21:17:23 2025 +0100 On machines that do not support the balanced profile the value of last_non_turbo_profile is invalid after initialization which might cause the driver to switch to an unsupported platform profile later. Fix this by only setting last_non_turbo_profile to supported platform profile values. Fixes: 191e21f ("platform/x86: acer-wmi: use an ACPI bitmap to set the platform profile choices") Signed-off-by: Armin Wolf <W_Armin@gmx.de> Tested-by: Hridesh MG <hridesh699@gmail.com> Reviewed-by: Hridesh MG <hridesh699@gmail.com> Link: https://lore.kernel.org/r/20250119201723.11102-3-W_Armin@gmx.de Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent efb504e commit d38b457

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

drivers/platform/x86/acer-wmi.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static bool platform_profile_support;
755755
* The profile used before turbo mode. This variable is needed for
756756
* returning from turbo mode when the mode key is in toggle mode.
757757
*/
758-
static int last_non_turbo_profile;
758+
static int last_non_turbo_profile = INT_MIN;
759759

760760
/* The most performant supported profile */
761761
static int acer_predator_v4_max_perf;
@@ -1997,32 +1997,43 @@ acer_predator_v4_platform_profile_probe(void *drvdata, unsigned long *choices)
19971997
/* Iterate through supported profiles in order of increasing performance */
19981998
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) {
19991999
set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
2000-
acer_predator_v4_max_perf =
2001-
ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
2000+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
2001+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
20022002
}
20032003

20042004
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) {
20052005
set_bit(PLATFORM_PROFILE_QUIET, choices);
2006-
acer_predator_v4_max_perf =
2007-
ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
2006+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
2007+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
20082008
}
20092009

20102010
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) {
20112011
set_bit(PLATFORM_PROFILE_BALANCED, choices);
2012-
acer_predator_v4_max_perf =
2013-
ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
2012+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
2013+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
20142014
}
20152015

20162016
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) {
20172017
set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices);
2018-
acer_predator_v4_max_perf =
2019-
ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
2018+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
2019+
2020+
/* We only use this profile as a fallback option in case no prior
2021+
* profile is supported.
2022+
*/
2023+
if (last_non_turbo_profile < 0)
2024+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
20202025
}
20212026

20222027
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO, &supported_profiles)) {
20232028
set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
2024-
acer_predator_v4_max_perf =
2025-
ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
2029+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
2030+
2031+
/* We need to handle the hypothetical case where only the turbo profile
2032+
* is supported. In this case the turbo toggle will essentially be a
2033+
* no-op.
2034+
*/
2035+
if (last_non_turbo_profile < 0)
2036+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
20262037
}
20272038

20282039
return 0;
@@ -2043,10 +2054,6 @@ static int acer_platform_profile_setup(struct platform_device *device)
20432054
return PTR_ERR(platform_profile_device);
20442055

20452056
platform_profile_support = true;
2046-
2047-
/* Set default non-turbo profile */
2048-
last_non_turbo_profile =
2049-
ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
20502057
}
20512058
return 0;
20522059
}
@@ -2064,6 +2071,10 @@ static int acer_thermal_profile_change(void)
20642071
if (cycle_gaming_thermal_profile) {
20652072
platform_profile_cycle();
20662073
} else {
2074+
/* Do nothing if no suitable platform profiles where found */
2075+
if (last_non_turbo_profile < 0)
2076+
return 0;
2077+
20672078
err = WMID_gaming_get_misc_setting(
20682079
ACER_WMID_MISC_SETTING_PLATFORM_PROFILE, &current_tp);
20692080
if (err)

0 commit comments

Comments
 (0)