Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1316954 > unrolled thread

[PATCH] mm/memcontrol: avoid a spurious gcc warning

Started byArnd Bergmann <arnd@arndb.de>
First post2016-01-25 17:20 +0100
Last post2016-01-25 20:00 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mm/memcontrol: avoid a spurious gcc warning Arnd Bergmann <arnd@arndb.de> - 2016-01-25 17:20 +0100
    Re: [PATCH] mm/memcontrol: avoid a spurious gcc warning Johannes Weiner <hannes@cmpxchg.org> - 2016-01-25 20:00 +0100

#1316954 — [PATCH] mm/memcontrol: avoid a spurious gcc warning

FromArnd Bergmann <arnd@arndb.de>
Date2016-01-25 17:20 +0100
Subject[PATCH] mm/memcontrol: avoid a spurious gcc warning
Message-ID<qUS20-6yn-55@gated-at.bofh.it>
When CONFIG_DEBUG_VM is set, the various VM_BUG_ON() confuse gcc to
the point where it cannot remember that 'memcg' is known to be initialized:

mm/memcontrol.c: In function 'mem_cgroup_can_attach':
mm/memcontrol.c:4791:9: warning: 'memcg' may be used uninitialized in this function [-Wmaybe-uninitialized]

On ARM gcc-5.1, the above happens when any two or more of the VM_BUG_ON()
are active, but not when I remove most or all of them. This is clearly
random behavior and the only way I've found to shut up the warning is
to add an explicit initialization.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 mm/memcontrol.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index d06cae2de783..9340eb981653 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4762,6 +4762,7 @@ static int mem_cgroup_can_attach(struct cgroup_taskset *tset)
 	 * multiple.
 	 */
 	p = NULL;
+	memcg = NULL;
 	cgroup_taskset_for_each_leader(leader, css, tset) {
 		WARN_ON_ONCE(p);
 		p = leader;
-- 
2.7.0

[toc] | [next] | [standalone]


#1317194

FromJohannes Weiner <hannes@cmpxchg.org>
Date2016-01-25 20:00 +0100
Message-ID<qUUwN-8gR-1@gated-at.bofh.it>
In reply to#1316954
Hi Arnd,

On Mon, Jan 25, 2016 at 04:45:50PM +0100, Arnd Bergmann wrote:
> When CONFIG_DEBUG_VM is set, the various VM_BUG_ON() confuse gcc to
> the point where it cannot remember that 'memcg' is known to be initialized:
> 
> mm/memcontrol.c: In function 'mem_cgroup_can_attach':
> mm/memcontrol.c:4791:9: warning: 'memcg' may be used uninitialized in this function [-Wmaybe-uninitialized]
> 
> On ARM gcc-5.1, the above happens when any two or more of the VM_BUG_ON()
> are active, but not when I remove most or all of them. This is clearly
> random behavior and the only way I've found to shut up the warning is
> to add an explicit initialization.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Thanks Arnd.

This has been fixed upstream already:

commit eed67d75b66748a498a0592d9704081a98509444
Author: Ross Zwisler <ross.zwisler@linux.intel.com>
Date:   Wed Dec 23 14:53:27 2015 -0700

    cgroup: Fix uninitialized variable warning
    
    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>
    Signed-off-by: Tejun Heo <tj@kernel.org>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web