Skip to content

Commit 25ca663

Browse files
committed
Merge tag 'amd-pstate-v6.19-2025-11-10' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/superm1/linux
Pull amd-pstate content for 6.19 (11/10/25) from Mario Liminciello: "* optimizations for parameter array handling * fix for mode changes with offline CPUs" * tag 'amd-pstate-v6.19-2025-11-10' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/superm1/linux: cpufreq/amd-pstate: Call cppc_set_auto_sel() only for online CPUs cpufreq/amd-pstate: Add static asserts for EPP indices cpufreq/amd-pstate: Fix some whitespace issues cpufreq/amd-pstate: Adjust return values in amd_pstate_update_status() cpufreq/amd-pstate: Make amd_pstate_get_mode_string() never return NULL cpufreq/amd-pstate: Drop NULL value from amd_pstate_mode_string cpufreq/amd-pstate: Use sysfs_match_string() for epp
2 parents 377e388 + bb31fef commit 25ca663

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ static const char * const amd_pstate_mode_string[] = {
6565
[AMD_PSTATE_PASSIVE] = "passive",
6666
[AMD_PSTATE_ACTIVE] = "active",
6767
[AMD_PSTATE_GUIDED] = "guided",
68-
NULL,
6968
};
69+
static_assert(ARRAY_SIZE(amd_pstate_mode_string) == AMD_PSTATE_MAX);
7070

7171
const char *amd_pstate_get_mode_string(enum amd_pstate_mode mode)
7272
{
73-
if (mode < 0 || mode >= AMD_PSTATE_MAX)
74-
return NULL;
73+
if (mode < AMD_PSTATE_UNDEFINED || mode >= AMD_PSTATE_MAX)
74+
mode = AMD_PSTATE_UNDEFINED;
7575
return amd_pstate_mode_string[mode];
7676
}
7777
EXPORT_SYMBOL_GPL(amd_pstate_get_mode_string);
@@ -110,6 +110,7 @@ enum energy_perf_value_index {
110110
EPP_INDEX_BALANCE_PERFORMANCE,
111111
EPP_INDEX_BALANCE_POWERSAVE,
112112
EPP_INDEX_POWERSAVE,
113+
EPP_INDEX_MAX,
113114
};
114115

115116
static const char * const energy_perf_strings[] = {
@@ -118,16 +119,17 @@ static const char * const energy_perf_strings[] = {
118119
[EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance",
119120
[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
120121
[EPP_INDEX_POWERSAVE] = "power",
121-
NULL
122122
};
123+
static_assert(ARRAY_SIZE(energy_perf_strings) == EPP_INDEX_MAX);
123124

124125
static unsigned int epp_values[] = {
125126
[EPP_INDEX_DEFAULT] = 0,
126127
[EPP_INDEX_PERFORMANCE] = AMD_CPPC_EPP_PERFORMANCE,
127128
[EPP_INDEX_BALANCE_PERFORMANCE] = AMD_CPPC_EPP_BALANCE_PERFORMANCE,
128129
[EPP_INDEX_BALANCE_POWERSAVE] = AMD_CPPC_EPP_BALANCE_POWERSAVE,
129130
[EPP_INDEX_POWERSAVE] = AMD_CPPC_EPP_POWERSAVE,
130-
};
131+
};
132+
static_assert(ARRAY_SIZE(epp_values) == EPP_INDEX_MAX);
131133

132134
typedef int (*cppc_mode_transition_fn)(int);
133135

@@ -183,7 +185,7 @@ static inline int get_mode_idx_from_str(const char *str, size_t size)
183185
{
184186
int i;
185187

186-
for (i=0; i < AMD_PSTATE_MAX; i++) {
188+
for (i = 0; i < AMD_PSTATE_MAX; i++) {
187189
if (!strncmp(str, amd_pstate_mode_string[i], size))
188190
return i;
189191
}
@@ -1137,16 +1139,15 @@ static ssize_t show_amd_pstate_hw_prefcore(struct cpufreq_policy *policy,
11371139
static ssize_t show_energy_performance_available_preferences(
11381140
struct cpufreq_policy *policy, char *buf)
11391141
{
1140-
int i = 0;
1141-
int offset = 0;
1142+
int offset = 0, i;
11421143
struct amd_cpudata *cpudata = policy->driver_data;
11431144

11441145
if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
11451146
return sysfs_emit_at(buf, offset, "%s\n",
11461147
energy_perf_strings[EPP_INDEX_PERFORMANCE]);
11471148

1148-
while (energy_perf_strings[i] != NULL)
1149-
offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i++]);
1149+
for (i = 0; i < ARRAY_SIZE(energy_perf_strings); i++)
1150+
offset += sysfs_emit_at(buf, offset, "%s ", energy_perf_strings[i]);
11501151

11511152
offset += sysfs_emit_at(buf, offset, "\n");
11521153

@@ -1157,15 +1158,10 @@ static ssize_t store_energy_performance_preference(
11571158
struct cpufreq_policy *policy, const char *buf, size_t count)
11581159
{
11591160
struct amd_cpudata *cpudata = policy->driver_data;
1160-
char str_preference[21];
11611161
ssize_t ret;
11621162
u8 epp;
11631163

1164-
ret = sscanf(buf, "%20s", str_preference);
1165-
if (ret != 1)
1166-
return -EINVAL;
1167-
1168-
ret = match_string(energy_perf_strings, -1, str_preference);
1164+
ret = sysfs_match_string(energy_perf_strings, buf);
11691165
if (ret < 0)
11701166
return -EINVAL;
11711167

@@ -1282,7 +1278,7 @@ static int amd_pstate_change_mode_without_dvr_change(int mode)
12821278
if (cpu_feature_enabled(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE)
12831279
return 0;
12841280

1285-
for_each_present_cpu(cpu) {
1281+
for_each_online_cpu(cpu) {
12861282
cppc_set_auto_sel(cpu, (cppc_state == AMD_PSTATE_PASSIVE) ? 0 : 1);
12871283
}
12881284

@@ -1353,9 +1349,8 @@ int amd_pstate_update_status(const char *buf, size_t size)
13531349
return -EINVAL;
13541350

13551351
mode_idx = get_mode_idx_from_str(buf, size);
1356-
1357-
if (mode_idx < 0 || mode_idx >= AMD_PSTATE_MAX)
1358-
return -EINVAL;
1352+
if (mode_idx < 0)
1353+
return mode_idx;
13591354

13601355
if (mode_state_machine[cppc_state][mode_idx]) {
13611356
guard(mutex)(&amd_pstate_driver_lock);

0 commit comments

Comments
 (0)