* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:30 ` Ross Zwisler
0 siblings, 0 replies; 11+ 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-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Dave Jones,
kernel-team-b10kYP2dOMg, 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
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] 11+ messages in thread* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:30 ` Ross Zwisler
0 siblings, 0 replies; 11+ 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] 11+ messages in thread* Re: [PATCH] cgroup: Fix uninitialized variable warning
2015-12-23 21:30 ` Ross Zwisler
(?)
@ 2015-12-23 21:35 ` Tejun Heo
[not found] ` <20151223213519.GM5003-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
-1 siblings, 1 reply; 11+ messages in thread
From: Tejun Heo @ 2015-12-23 21:35 UTC (permalink / raw)
To: Ross Zwisler
Cc: Linus Torvalds, Li Zefan, Daniel Wagner, Johannes Weiner, cgroups,
linux-kernel, Dave Jones, kernel-team, Aleksa Sarai, Michal Hocko,
Ingo Molnar, Peter Zijlstra, Neil Horman
Hello, Ross.
On Wed, Dec 23, 2015 at 02:30:40PM -0700, Ross Zwisler wrote:
> static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
> {
> struct cgroup_subsys_state *css;
> - struct mem_cgroup *memcg;
> + struct mem_cgroup *memcg = NULL;
It's one thing to add spurious init to shut up gcc
> @@ -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)
and to another to add an additional processing on it.
Please note which gcc version you were using in the commit description
and mark the init with a comment.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:53 ` Ross Zwisler
0 siblings, 0 replies; 11+ 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-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Dave Jones,
kernel-team-b10kYP2dOMg, 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
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] 11+ messages in thread* [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-23 21:53 ` Ross Zwisler
0 siblings, 0 replies; 11+ 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] 11+ messages in thread[parent not found: <1450907607-5060-1-git-send-email-ross.zwisler-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH] cgroup: Fix uninitialized variable warning
2015-12-23 21:53 ` Ross Zwisler
@ 2015-12-28 15:45 ` Tejun Heo
-1 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2015-12-28 15:45 UTC (permalink / raw)
To: Ross Zwisler
Cc: Linus Torvalds, Li Zefan, Daniel Wagner, Johannes Weiner,
cgroups-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA, Dave Jones,
kernel-team-b10kYP2dOMg, Aleksa Sarai, Michal Hocko, Ingo Molnar,
Peter Zijlstra, Neil Horman
On Wed, Dec 23, 2015 at 02:53:27PM -0700, Ross Zwisler wrote:
> 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Applied to cgroup/for-4.5.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] cgroup: Fix uninitialized variable warning
@ 2015-12-28 15:45 ` Tejun Heo
0 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2015-12-28 15:45 UTC (permalink / raw)
To: Ross Zwisler
Cc: Linus Torvalds, Li Zefan, Daniel Wagner, Johannes Weiner, cgroups,
linux-kernel, Dave Jones, kernel-team, Aleksa Sarai, Michal Hocko,
Ingo Molnar, Peter Zijlstra, Neil Horman
On Wed, Dec 23, 2015 at 02:53:27PM -0700, Ross Zwisler wrote:
> 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>
Applied to cgroup/for-4.5.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2015-12-28 15:45 UTC | newest]
Thread overview: 11+ 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:30 ` Ross Zwisler
2015-12-23 21:35 ` Tejun Heo
[not found] ` <20151223213519.GM5003-qYNAdHglDFBN0TnZuCh8vA@public.gmane.org>
2015-12-23 21:38 ` Ross Zwisler
2015-12-23 21:38 ` Ross Zwisler
[not found] ` <20151223213813.GA21287-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-12-23 21:41 ` Tejun Heo
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-23 21:53 ` Ross Zwisler
[not found] ` <1450907607-5060-1-git-send-email-ross.zwisler-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-12-28 15:45 ` Tejun Heo
2015-12-28 15:45 ` Tejun Heo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.