Re: [PATCH v4] cpufreq: amd-pstate: fix the memory to free after epp exist

From: Limonciello, Mario
Date: Thu May 16 2024 - 03:47:23 EST




On 5/16/2024 1:30 AM, zhida312@xxxxxxxxxxx wrote:
From: andypma <andypma.tencent.com>

the cpudata memory from kzmalloc in epp init function is
not free after epp exist, so we should free it.

Signed-off-by: Peng Ma <andypma@xxxxxxxxxxx>

Changes from v3 to v4:
update subject used git command "git format-patch -1 -v x"

Changes from v2 to v3:
update Signed-off-by to Peng Ma <andypma@xxxxxxxxxxx>.
set a space between if and "(".

Changes from v1 to v2:
check whether it is empty before releasing
set driver_data is NULL after free
---

Thanks for your submission!

I would prefer the change list below the cut list, but otherwise this is fine. Maybe Rafael can modify that while committing.

Acked-by: Mario Limonciello <mario.limonciello@xxxxxxx>

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 6a342b0c0140..1b7e82a0ad2e 100644
--- a/drivers/cpufreq/amd-pstate.c
+++ b/drivers/cpufreq/amd-pstate.c
@@ -1441,6 +1441,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;
}