From: Paul E. McKenney Date: Thu, 29 Nov 2012 21:49:00 +0000 (-0800) Subject: rcu: Silence compiler array out-of-bounds false positive X-Git-Tag: v3.9-rc1~175^2~2^2^2~6 X-Git-Url: http://pileus.org/git/?a=commitdiff_plain;h=4930521ae10fd28ebc713107fd243c8044a95415;p=~andy%2Flinux rcu: Silence compiler array out-of-bounds false positive It turns out that gcc 4.8 warns on array indexes being out of bounds unless it can prove otherwise. It gives this warning on some RCU initialization code. Because this is far from any fastpath, add an explicit check for array bounds and panic if so. This gives the compiler enough information to figure out that the array index is never out of bounds. However, if a similar false positive occurs on a fastpath, it will probably be necessary to tell the compiler to keep its array-index anxieties to itself. ;-) Markus Trippelsdorf Signed-off-by: Paul E. McKenney Reviewed-by: Josh Triplett --- diff --git a/kernel/rcutree.c b/kernel/rcutree.c index d145796bd61..e0d98157fbe 100644 --- a/kernel/rcutree.c +++ b/kernel/rcutree.c @@ -2938,6 +2938,10 @@ static void __init rcu_init_one(struct rcu_state *rsp, BUILD_BUG_ON(MAX_RCU_LVLS > ARRAY_SIZE(buf)); /* Fix buf[] init! */ + /* Silence gcc 4.8 warning about array index out of range. */ + if (rcu_num_lvls > RCU_NUM_LVLS) + panic("rcu_init_one: rcu_num_lvls overflow"); + /* Initialize the level-tracking arrays. */ for (i = 0; i < rcu_num_lvls; i++)