mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] rcu: Shut up bogus gcc array bounds warning
@ 2015-07-09 13:34 Alexander Gordeev
  2015-07-09 17:01 ` Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Gordeev @ 2015-07-09 13:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Alexander Gordeev, Paul E. McKenney

Because gcc does not realize a loop would not be entered ever
(i.e. in case of rcu_num_lvls == 1):

  for (i = 1; i < rcu_num_lvls; i++)
	  rsp->level[i] = rsp->level[i - 1] + levelcnt[i - 1];

some compiler (pre- 5.x?) versions give a bogus warning:

  kernel/rcu/tree.c: In function ‘rcu_init_one.isra.55’:
  kernel/rcu/tree.c:4108:13: warning: array subscript is above array bounds [-Warray-bounds]
     rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
               ^
Fix that warning by adding an extra item to rcu_state::level[]
array. Once the bogus warning is fixed in gcc and kernel drops
support of older versions, the dummy item may be removed from
the array.

Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Suggested-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
 kernel/rcu/tree.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 852b810..543ba72 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -451,7 +451,9 @@ do {									\
  */
 struct rcu_state {
 	struct rcu_node node[NUM_RCU_NODES];	/* Hierarchy. */
-	struct rcu_node *level[RCU_NUM_LVLS];	/* Hierarchy levels. */
+	struct rcu_node *level[RCU_NUM_LVLS + 1];
+						/* Hierarchy levels (+1 to */
+						/*  shut bogus gcc warning) */
 	u8 flavor_mask;				/* bit in flavor mask. */
 	struct rcu_data __percpu *rda;		/* pointer of percu rcu_data. */
 	void (*call)(struct rcu_head *head,	/* call_rcu() flavor. */
-- 
1.8.3.1


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

* Re: [PATCH] rcu: Shut up bogus gcc array bounds warning
  2015-07-09 13:34 [PATCH] rcu: Shut up bogus gcc array bounds warning Alexander Gordeev
@ 2015-07-09 17:01 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2015-07-09 17:01 UTC (permalink / raw)
  To: Alexander Gordeev; +Cc: linux-kernel

On Thu, Jul 09, 2015 at 03:34:23PM +0200, Alexander Gordeev wrote:
> Because gcc does not realize a loop would not be entered ever
> (i.e. in case of rcu_num_lvls == 1):
> 
>   for (i = 1; i < rcu_num_lvls; i++)
> 	  rsp->level[i] = rsp->level[i - 1] + levelcnt[i - 1];
> 
> some compiler (pre- 5.x?) versions give a bogus warning:
> 
>   kernel/rcu/tree.c: In function ‘rcu_init_one.isra.55’:
>   kernel/rcu/tree.c:4108:13: warning: array subscript is above array bounds [-Warray-bounds]
>      rsp->level[i] = rsp->level[i - 1] + rsp->levelcnt[i - 1];
>                ^
> Fix that warning by adding an extra item to rcu_state::level[]
> array. Once the bogus warning is fixed in gcc and kernel drops
> support of older versions, the dummy item may be removed from
> the array.
> 
> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> Suggested-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> Signed-off-by: Alexander Gordeev <agordeev@redhat.com>

Queued, thank you!

							Thanx, Paul

> ---
>  kernel/rcu/tree.h | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
> index 852b810..543ba72 100644
> --- a/kernel/rcu/tree.h
> +++ b/kernel/rcu/tree.h
> @@ -451,7 +451,9 @@ do {									\
>   */
>  struct rcu_state {
>  	struct rcu_node node[NUM_RCU_NODES];	/* Hierarchy. */
> -	struct rcu_node *level[RCU_NUM_LVLS];	/* Hierarchy levels. */
> +	struct rcu_node *level[RCU_NUM_LVLS + 1];
> +						/* Hierarchy levels (+1 to */
> +						/*  shut bogus gcc warning) */
>  	u8 flavor_mask;				/* bit in flavor mask. */
>  	struct rcu_data __percpu *rda;		/* pointer of percu rcu_data. */
>  	void (*call)(struct rcu_head *head,	/* call_rcu() flavor. */
> -- 
> 1.8.3.1
> 


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

end of thread, other threads:[~2015-07-09 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-09 13:34 [PATCH] rcu: Shut up bogus gcc array bounds warning Alexander Gordeev
2015-07-09 17:01 ` Paul E. McKenney

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

Powered by JetHome