Skip to content

Commit 3ef4ea5

Browse files
Wer-Wolfij-intel
authored andcommitted
platform/x86: acer-wmi: Fix initialization of last_non_turbo_profile
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 <[email protected]> Tested-by: Hridesh MG <[email protected]> Reviewed-by: Hridesh MG <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent f6bfa25 commit 3ef4ea5

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
@@ -792,7 +792,7 @@ static bool platform_profile_support;
792792
* The profile used before turbo mode. This variable is needed for
793793
* returning from turbo mode when the mode key is in toggle mode.
794794
*/
795-
static int last_non_turbo_profile;
795+
static int last_non_turbo_profile = INT_MIN;
796796

797797
/* The most performant supported profile */
798798
static int acer_predator_v4_max_perf;
@@ -2034,32 +2034,43 @@ acer_predator_v4_platform_profile_probe(void *drvdata, unsigned long *choices)
20342034
/* Iterate through supported profiles in order of increasing performance */
20352035
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_ECO, &supported_profiles)) {
20362036
set_bit(PLATFORM_PROFILE_LOW_POWER, choices);
2037-
acer_predator_v4_max_perf =
2038-
ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
2037+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
2038+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_ECO;
20392039
}
20402040

20412041
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET, &supported_profiles)) {
20422042
set_bit(PLATFORM_PROFILE_QUIET, choices);
2043-
acer_predator_v4_max_perf =
2044-
ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
2043+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
2044+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_QUIET;
20452045
}
20462046

20472047
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED, &supported_profiles)) {
20482048
set_bit(PLATFORM_PROFILE_BALANCED, choices);
2049-
acer_predator_v4_max_perf =
2050-
ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
2049+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
2050+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
20512051
}
20522052

20532053
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE, &supported_profiles)) {
20542054
set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices);
2055-
acer_predator_v4_max_perf =
2056-
ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
2055+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
2056+
2057+
/* We only use this profile as a fallback option in case no prior
2058+
* profile is supported.
2059+
*/
2060+
if (last_non_turbo_profile < 0)
2061+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_PERFORMANCE;
20572062
}
20582063

20592064
if (test_bit(ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO, &supported_profiles)) {
20602065
set_bit(PLATFORM_PROFILE_PERFORMANCE, choices);
2061-
acer_predator_v4_max_perf =
2062-
ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
2066+
acer_predator_v4_max_perf = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
2067+
2068+
/* We need to handle the hypothetical case where only the turbo profile
2069+
* is supported. In this case the turbo toggle will essentially be a
2070+
* no-op.
2071+
*/
2072+
if (last_non_turbo_profile < 0)
2073+
last_non_turbo_profile = ACER_PREDATOR_V4_THERMAL_PROFILE_TURBO;
20632074
}
20642075

20652076
return 0;
@@ -2080,10 +2091,6 @@ static int acer_platform_profile_setup(struct platform_device *device)
20802091
return PTR_ERR(platform_profile_device);
20812092

20822093
platform_profile_support = true;
2083-
2084-
/* Set default non-turbo profile */
2085-
last_non_turbo_profile =
2086-
ACER_PREDATOR_V4_THERMAL_PROFILE_BALANCED;
20872094
}
20882095
return 0;
20892096
}
@@ -2101,6 +2108,10 @@ static int acer_thermal_profile_change(void)
21012108
if (cycle_gaming_thermal_profile) {
21022109
platform_profile_cycle();
21032110
} else {
2111+
/* Do nothing if no suitable platform profiles where found */
2112+
if (last_non_turbo_profile < 0)
2113+
return 0;
2114+
21042115
err = WMID_gaming_get_misc_setting(
21052116
ACER_WMID_MISC_SETTING_PLATFORM_PROFILE, &current_tp);
21062117
if (err)

0 commit comments

Comments
 (0)