sched/cpufreq: Fix kobject memleak [Linux 5.1]

sched/cpufreq: Fix kobject memleak [Linux 5.1]

This Linux kernel change "sched/cpufreq: Fix kobject memleak" is included in the Linux 5.1 release. This change is authored by Tobin C. Harding <tobin [at] kernel.org> on Tue Apr 30 10:11:44 2019 +1000. The commit for this change in Linux stable tree is 9a4f26c (patch).

sched/cpufreq: Fix kobject memleak

Currently the error return path from kobject_init_and_add() is not
followed by a call to kobject_put() - which means we are leaking
the kobject.

Fix it by adding a call to kobject_put() in the error path of
kobject_init_and_add().

Signed-off-by: Tobin C. Harding <tobin@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tobin C. Harding <tobin@kernel.org>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Link: http://lkml.kernel.org/r/20190430001144.24890-1-tobin@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>

There is one line of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 kernel/sched/cpufreq_schedutil.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 5c41ea3..3638d23 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -771,6 +771,7 @@ static int sugov_init(struct cpufreq_policy *policy)
    return 0;

 fail:
+   kobject_put(&tunables->attr_set.kobj);
    policy->governor_data = NULL;
    sugov_tunables_free(tunables);

Leave a Reply

Your email address will not be published. Required fields are marked *