diff mbox series

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

Message ID 1583069198-21060-1-git-send-email-qiwuchen55@gmail.com (mailing list archive)
State Rejected, archived
Headers show
Series cpufreq: fix a mem leak caused by policy->max_freq_req in cpufreq_policy_free() | expand

Commit Message

chenqiwu March 1, 2020, 1:26 p.m. UTC
From: chenqiwu <chenqiwu@xiaomi.com>

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

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
 drivers/cpufreq/cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Rafael J. Wysocki March 1, 2020, 8:09 p.m. UTC | #1
On Sun, Mar 1, 2020 at 2:26 PM <qiwuchen55@gmail.com> wrote:
>
> From: chenqiwu <chenqiwu@xiaomi.com>
>
> 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!

> Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> ---
>  drivers/cpufreq/cpufreq.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index cbe6c94..6756f7a 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -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
>
Viresh Kumar March 2, 2020, 4:23 a.m. UTC | #2
On 01-03-20, 21:09, Rafael J. Wysocki wrote:
> On Sun, Mar 1, 2020 at 2:26 PM <qiwuchen55@gmail.com> wrote:
> >
> > From: chenqiwu <chenqiwu@xiaomi.com>
> >
> > 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

> Thanks!
> 
> > Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
> > ---
> >  drivers/cpufreq/cpufreq.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> > index cbe6c94..6756f7a 100644
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -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.
diff mbox series

Patch

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index cbe6c94..6756f7a 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -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);