[PATCH AUTOSEL 6.9 25/28] cpufreq: amd-pstate: fix memory leak on CPU EPP exit

From: Sasha Levin
Date: Wed Jun 05 2024 - 07:56:43 EST


From: Peng Ma <andypma@xxxxxxxxxxx>

[ Upstream commit cea04f3d9aeebda9d9c063c0dfa71e739c322c81 ]

The cpudata memory from kzalloc() in amd_pstate_epp_cpu_init() is
not freed in the analogous exit function, so fix that.

Signed-off-by: Peng Ma <andypma@xxxxxxxxxxx>
Acked-by: Mario Limonciello <mario.limonciello@xxxxxxx>
Reviewed-by: Perry Yuan <Perry.Yuan@xxxxxxx>
[ rjw: Subject and changelog edits ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/cpufreq/amd-pstate.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c
index 2015c9fcc3c91..097268e7b0aa8 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1378,6 +1378,13 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)

static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy)
{
+ struct amd_cpudata *cpudata = policy->driver_data;
+
+ if (cpudata) {
+ kfree(cpudata);
+ policy->driver_data = NULL;
+ }
+
pr_debug("CPU %d exiting\n", policy->cpu);
return 0;
}
--
2.43.0