Skip to content

Commit 6c093d5

Browse files
committed
cpufreq/amd-pstate: convert mutex use to guard()
Using scoped guard declaration will unlock mutexes automatically. Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com> Link: https://lore.kernel.org/r/20241209185248.16301-5-mario.limonciello@amd.com Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
1 parent 4dcd130 commit 6c093d5

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

drivers/cpufreq/amd-pstate.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -758,12 +758,12 @@ static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)
758758
pr_err("Boost mode is not supported by this processor or SBIOS\n");
759759
return -EOPNOTSUPP;
760760
}
761-
mutex_lock(&amd_pstate_driver_lock);
761+
guard(mutex)(&amd_pstate_driver_lock);
762+
762763
ret = amd_pstate_cpu_boost_update(policy, state);
763764
WRITE_ONCE(cpudata->boost_state, !ret ? state : false);
764765
policy->boost_enabled = !ret ? state : false;
765766
refresh_frequency_limits(policy);
766-
mutex_unlock(&amd_pstate_driver_lock);
767767

768768
return ret;
769769
}
@@ -854,7 +854,8 @@ static void amd_pstate_update_limits(unsigned int cpu)
854854
if (!amd_pstate_prefcore)
855855
return;
856856

857-
mutex_lock(&amd_pstate_driver_lock);
857+
guard(mutex)(&amd_pstate_driver_lock);
858+
858859
ret = amd_get_highest_perf(cpu, &cur_high);
859860
if (ret)
860861
goto free_cpufreq_put;
@@ -874,7 +875,6 @@ static void amd_pstate_update_limits(unsigned int cpu)
874875
if (!highest_perf_changed)
875876
cpufreq_update_policy(cpu);
876877

877-
mutex_unlock(&amd_pstate_driver_lock);
878878
}
879879

880880
/*
@@ -1203,11 +1203,11 @@ static ssize_t store_energy_performance_preference(
12031203
if (ret < 0)
12041204
return -EINVAL;
12051205

1206-
mutex_lock(&amd_pstate_limits_lock);
1206+
guard(mutex)(&amd_pstate_limits_lock);
1207+
12071208
ret = amd_pstate_set_energy_pref_index(cpudata, ret);
1208-
mutex_unlock(&amd_pstate_limits_lock);
12091209

1210-
return ret ?: count;
1210+
return ret ? ret : count;
12111211
}
12121212

12131213
static ssize_t show_energy_performance_preference(
@@ -1371,13 +1371,10 @@ EXPORT_SYMBOL_GPL(amd_pstate_update_status);
13711371
static ssize_t status_show(struct device *dev,
13721372
struct device_attribute *attr, char *buf)
13731373
{
1374-
ssize_t ret;
13751374

1376-
mutex_lock(&amd_pstate_driver_lock);
1377-
ret = amd_pstate_show_status(buf);
1378-
mutex_unlock(&amd_pstate_driver_lock);
1375+
guard(mutex)(&amd_pstate_driver_lock);
13791376

1380-
return ret;
1377+
return amd_pstate_show_status(buf);
13811378
}
13821379

13831380
static ssize_t status_store(struct device *a, struct device_attribute *b,
@@ -1386,9 +1383,8 @@ static ssize_t status_store(struct device *a, struct device_attribute *b,
13861383
char *p = memchr(buf, '\n', count);
13871384
int ret;
13881385

1389-
mutex_lock(&amd_pstate_driver_lock);
1386+
guard(mutex)(&amd_pstate_driver_lock);
13901387
ret = amd_pstate_update_status(buf, p ? p - buf : count);
1391-
mutex_unlock(&amd_pstate_driver_lock);
13921388

13931389
return ret < 0 ? ret : count;
13941390
}
@@ -1689,7 +1685,7 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
16891685

16901686
min_perf = READ_ONCE(cpudata->lowest_perf);
16911687

1692-
mutex_lock(&amd_pstate_limits_lock);
1688+
guard(mutex)(&amd_pstate_limits_lock);
16931689

16941690
if (trace_amd_pstate_epp_perf_enabled()) {
16951691
trace_amd_pstate_epp_perf(cpudata->cpu, cpudata->highest_perf,
@@ -1700,8 +1696,6 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
17001696
amd_pstate_update_perf(cpudata, min_perf, 0, min_perf, false);
17011697
amd_pstate_set_epp(cpudata, AMD_CPPC_EPP_BALANCE_POWERSAVE);
17021698

1703-
mutex_unlock(&amd_pstate_limits_lock);
1704-
17051699
return 0;
17061700
}
17071701

@@ -1730,13 +1724,11 @@ static int amd_pstate_epp_resume(struct cpufreq_policy *policy)
17301724
struct amd_cpudata *cpudata = policy->driver_data;
17311725

17321726
if (cpudata->suspended) {
1733-
mutex_lock(&amd_pstate_limits_lock);
1727+
guard(mutex)(&amd_pstate_limits_lock);
17341728

17351729
/* enable amd pstate from suspend state*/
17361730
amd_pstate_epp_reenable(cpudata);
17371731

1738-
mutex_unlock(&amd_pstate_limits_lock);
1739-
17401732
cpudata->suspended = false;
17411733
}
17421734

0 commit comments

Comments
 (0)