From fa73208bbfa0c16e4677695073632edb9662343e Mon Sep 17 00:00:00 2001
Message-Id: <fa73208bbfa0c16e4677695073632edb9662343e.1371569345.git.viresh.kumar@linaro.org>
From: Viresh Kumar <viresh.kumar@linaro.org>
Date: Tue, 11 Jun 2013 14:43:43 +0530
Subject: [PATCH] sched: Fix memory leakage in build_sched_groups()

In build_sched_groups() we don't need to call get_group() for cpus which are
already covered in previous iterations. Calling get_group() would mark the group
used and eventually leak it since we wouldn't connect it and not find it again
to free it.

This will happen only in cases where sg->cpumask contained more than one cpu
(For any topology level). This patch would free sg's memory for all cpus leaving
the group leader as the group isn't marked used now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 kernel/sched/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 4abc743..27842f5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5344,12 +5344,12 @@ build_sched_groups(struct sched_domain *sd, int cpu)
 
 	for_each_cpu(i, span) {
 		struct sched_group *sg;
-		int group = get_group(i, sdd, &sg);
-		int j;
+		int group, j;
 
 		if (cpumask_test_cpu(i, covered))
 			continue;
 
+		group = get_group(i, sdd, &sg);
 		cpumask_clear(sched_group_cpus(sg));
 		sg->sgp->power = 0;
 		cpumask_setall(sched_group_mask(sg));
-- 
1.7.12.rc2.18.g61b472e

