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 <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Rafael J. Wysocki <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Tobin C. Harding <[email protected]>
Cc: Vincent Guittot <[email protected]>
Cc: Viresh Kumar <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>

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 *