[PATCH] cpufreq/amd-pstate: Restore previous EPP if profile_name allocation fails
From: Xueqin Luo
Date: Tue Aug 25 2026 - 09:20:27 EST
amd_pstate_set_dynamic_epp() first applies the EPP value derived from
the current platform profile via amd_pstate_set_epp() and only then
allocates the profile name and registers the platform profile handler
and the power supply notifier. All failures after the EPP has been
programmed jump to the cleanup label, which restores the previously
programmed EPP value.
However, if the kasprintf() of the profile name fails, the function
returns -ENOMEM directly, bypassing the cleanup label, so the EPP value
programmed above is never rolled back even though enabling dynamic EPP
has failed.
Make the allocation failure path jump to the cleanup label as well, so
that the previous EPP value is restored consistently on all error
paths.
Fixes: b7294b627598 ("cpufreq/amd-pstate: Add dynamic EPP as an "energy_performance_preference" mode")
Signed-off-by: Xueqin Luo <luoxueqin@xxxxxxxxxx>
---
drivers/cpufreq/amd-pstate.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index d4ff8b228f86..083094d23bff 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1292,8 +1292,10 @@ static int amd_pstate_set_dynamic_epp(struct cpufreq_policy *policy)
return ret;
cpudata->profile_name = kasprintf(GFP_KERNEL, "amd-pstate-epp-cpu%d", cpudata->cpu);
- if (!cpudata->profile_name)
- return -ENOMEM;
+ if (!cpudata->profile_name) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
cpudata->ppdev = platform_profile_register(get_cpu_device(policy->cpu),
cpudata->profile_name,
--
2.43.0