Skip to content

Commit 7e17f48

Browse files
committed
cpufreq/amd-pstate: Use sysfs_match_string() for epp
Rather than scanning the buffer and manually matching the string use the sysfs macros. Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
1 parent e9a6fb0 commit 7e17f48

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

drivers/cpufreq/amd-pstate.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ static const char * const energy_perf_strings[] = {
118118
[EPP_INDEX_BALANCE_PERFORMANCE] = "balance_performance",
119119
[EPP_INDEX_BALANCE_POWERSAVE] = "balance_power",
120120
[EPP_INDEX_POWERSAVE] = "power",
121-
NULL
122121
};
123122

124123
static unsigned int epp_values[] = {
@@ -1137,16 +1136,15 @@ static ssize_t show_amd_pstate_hw_prefcore(struct cpufreq_policy *policy,
11371136
static ssize_t show_energy_performance_available_preferences(
11381137
struct cpufreq_policy *policy, char *buf)
11391138
{
1140-
int i = 0;
1141-
int offset = 0;
1139+
int offset = 0, i;
11421140
struct amd_cpudata *cpudata = policy->driver_data;
11431141

11441142
if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE)
11451143
return sysfs_emit_at(buf, offset, "%s\n",
11461144
energy_perf_strings[EPP_INDEX_PERFORMANCE]);
11471145

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

11511149
offset += sysfs_emit_at(buf, offset, "\n");
11521150

@@ -1157,15 +1155,10 @@ static ssize_t store_energy_performance_preference(
11571155
struct cpufreq_policy *policy, const char *buf, size_t count)
11581156
{
11591157
struct amd_cpudata *cpudata = policy->driver_data;
1160-
char str_preference[21];
11611158
ssize_t ret;
11621159
u8 epp;
11631160

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);
1161+
ret = sysfs_match_string(energy_perf_strings, buf);
11691162
if (ret < 0)
11701163
return -EINVAL;
11711164

0 commit comments

Comments
 (0)