public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:30 Ross Zwisler
  2015-12-23 21:35 ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Ross Zwisler @ 2015-12-23 21:30 UTC (permalink / raw)
  To: Linus Torvalds, Tejun Heo
  Cc: Ross Zwisler, Li Zefan, Daniel Wagner, Johannes Weiner, cgroups,
	linux-kernel, Dave Jones, kernel-team, Aleksa Sarai, Michal Hocko,
	Ingo Molnar, Peter Zijlstra, Neil Horman

Commit 1f7dd3e5a6e4 ("cgroup: fix handling of multi-destination migration
from subtree_control enabling") introduced the following compiler warning:

mm/memcontrol.c: In function ‘mem_cgroup_can_attach’:
mm/memcontrol.c:4790:9: warning: ‘memcg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   mc.to = memcg;
         ^
Fix this by initializing 'memcg' to NULL and then verifying that it is set
to a value before dereferencing it.

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
---

This issue is present in v4.4-rc5 and later.

---
 mm/memcontrol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e234c21..69a28b3 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4782,7 +4782,7 @@ static void mem_cgroup_clear_mc(void)
 static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
 {
 	struct cgroup_subsys_state *css;
-	struct mem_cgroup *memcg;
+	struct mem_cgroup *memcg = NULL;
 	struct mem_cgroup *from;
 	struct task_struct *leader, *p;
 	struct mm_struct *mm;
@@ -4805,7 +4805,7 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
 		p = leader;
 		memcg = mem_cgroup_from_css(css);
 	}
-	if (!p)
+	if (!p || !memcg)
 		return 0;
 
 	/*
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:53 Ross Zwisler
  2015-12-28 15:45 ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Ross Zwisler @ 2015-12-23 21:53 UTC (permalink / raw)
  To: Linus Torvalds, Tejun Heo
  Cc: Ross Zwisler, Li Zefan, Daniel Wagner, Johannes Weiner, cgroups,
	linux-kernel, Dave Jones, kernel-team, Aleksa Sarai, Michal Hocko,
	Ingo Molnar, Peter Zijlstra, Neil Horman

Commit 1f7dd3e5a6e4 ("cgroup: fix handling of multi-destination migration
from subtree_control enabling") introduced the following compiler warning:

mm/memcontrol.c: In function ‘mem_cgroup_can_attach’:
mm/memcontrol.c:4790:9: warning: ‘memcg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   mc.to = memcg;
         ^

Fix this by initializing 'memcg' to NULL.

This was found using gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6).

Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
---
 mm/memcontrol.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 48b22c3..ffd9750 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4735,7 +4735,7 @@ static void mem_cgroup_clear_mc(void)
 static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
 {
 	struct cgroup_subsys_state *css;
-	struct mem_cgroup *memcg;
+	struct mem_cgroup *memcg = NULL; /* unneeded init to make gcc happy */
 	struct mem_cgroup *from;
 	struct task_struct *leader, *p;
 	struct mm_struct *mm;
-- 
2.6.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-12-28 15:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-23 21:30 [PATCH] cgroup: Fix uninitialized variable warning Ross Zwisler
2015-12-23 21:35 ` Tejun Heo
2015-12-23 21:38   ` Ross Zwisler
2015-12-23 21:41     ` Tejun Heo
  -- strict thread matches above, loose matches on Subject: below --
2015-12-23 21:53 Ross Zwisler
2015-12-28 15:45 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox