Skip to contentSkip to conversation

cpufreq: fix a mem leak caused by policy->max_freq_req in cpufreq_policy_free()

PATCH In review [email protected] 3 participants 3 messages Mar 1, 2020 – Mar 2, 2020 CPU frequency scaling framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpufreq: fix a mem leak caused by policy->max_freq_req in cpufreq_policy_free()

From: chenqiwu <[email protected]>

There is a mem leak in cpufreq_policy_free() that the resource of policy->max_freq_req pointer is not free.

---
 drivers/cpufreq/cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/cpufreq/cpufreq.c +2 -0
index cbe6c94..6756f7a 100644
@@ -1280,6 +1280,8 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
 		blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
 					     CPUFREQ_REMOVE_POLICY, policy);
 		freq_qos_remove_request(policy->max_freq_req);
+		kfree(policy->max_freq_req);
+		policy->max_freq_req = NULL;
 	}
 
 	freq_qos_remove_request(policy->min_freq_req);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 5 lines · On Sun, Mar 1, 2020 at 2:26 PM <[email protected]> wrote:

From: chenqiwu <[email protected]>

There is a mem leak in cpufreq_policy_free() that the resource of policy->max_freq_req pointer is not free.

That's incorrect AFAICS.

Thanks!

Quoted 21 lines
---
 drivers/cpufreq/cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/cpufreq/cpufreq.c +2 -1
index cbe6c94..6756f7a 100644
@@ -1280,6 +1280,8 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
                blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
                                             CPUFREQ_REMOVE_POLICY, policy);
                freq_qos_remove_request(policy->max_freq_req);
+               kfree(policy->max_freq_req);
+               policy->max_freq_req = NULL;
        }
 
        freq_qos_remove_request(policy->min_freq_req);
--

1.9.1

maintainer
#2 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 5 lines · On Sun, Mar 1, 2020 at 2:26 PM <[email protected]> wrote:

From: chenqiwu <[email protected]>

There is a mem leak in cpufreq_policy_free() that the resource of policy->max_freq_req pointer is not free.

That's incorrect AFAICS.

+1

Quoted 7 lines

Thanks!

Quoted 5 lines
---
 drivers/cpufreq/cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 10 lines

drivers/cpufreq/cpufreq.c static void cpufreq_policy_free(struct cpufreq_policy *policy) · line 1284

Quoted 10 lines
drivers/cpufreq/cpufreq.c +2 -0
index cbe6c94..6756f7a 100644
@@ -1280,6 +1280,8 @@ static void cpufreq_policy_free(struct cpufreq_policy *policy)
                blocking_notifier_call_chain(&cpufreq_policy_notifier_list,
                                             CPUFREQ_REMOVE_POLICY, policy);
                freq_qos_remove_request(policy->max_freq_req);
+               kfree(policy->max_freq_req);
+               policy->max_freq_req = NULL;

Memory for both min_freq_req and max_freq_req is allocated together and so we don't need to free max_freq_req separately.

Signature · 1 line
viresh