All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning
@ 2016-07-21 19:28 Arnd Bergmann
  2016-07-22  0:11 ` Gavin Shan
  2016-07-25 17:33 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2016-07-21 19:28 UTC (permalink / raw)
  To: David S. Miller
  Cc: Arnd Bergmann, Gavin Shan, Joel Stanley, netdev, linux-kernel

gcc-4.9 and higher warn about the newly added NSCI code:

net/ncsi/ncsi-manage.c: In function 'ncsi_process_next_channel':
net/ncsi/ncsi-manage.c:1003:2: error: 'old_state' may be used uninitialized in this function [-Werror=maybe-uninitialized]

The warning is a false positive and therefore harmless, but it would be good to
avoid it anyway. I have determined that the barrier in the spin_unlock_irqsave()
is what confuses gcc to the point that it cannot track whether the variable
was unused or not.

This rearranges the code in a way that makes it obvious to gcc that old_state
is always initialized at the time of use, functionally this should not
change anything.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 net/ncsi/ncsi-manage.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index d627a39ddcd0..ef017b871857 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -982,23 +982,18 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
 	spin_lock_irqsave(&ndp->lock, flags);
 	nc = list_first_or_null_rcu(&ndp->channel_queue,
 				    struct ncsi_channel, link);
-	if (nc) {
-		old_state = xchg(&nc->state, NCSI_CHANNEL_INVISIBLE);
-		list_del_init(&nc->link);
+	if (!nc) {
+		spin_unlock_irqrestore(&ndp->lock, flags);
+		goto out;
 	}
+
+	old_state = xchg(&nc->state, NCSI_CHANNEL_INVISIBLE);
+	list_del_init(&nc->link);
+
 	spin_unlock_irqrestore(&ndp->lock, flags);
 
 	ndp->active_channel = nc;
-	ndp->active_package = nc ? nc->package : NULL;
-	if (!nc) {
-		if (ndp->flags & NCSI_DEV_RESHUFFLE) {
-			ndp->flags &= ~NCSI_DEV_RESHUFFLE;
-			return ncsi_choose_active_channel(ndp);
-		}
-
-		ncsi_report_link(ndp, false);
-		return -ENODEV;
-	}
+	ndp->active_package = nc->package;
 
 	switch (old_state) {
 	case NCSI_CHANNEL_INACTIVE:
@@ -1017,6 +1012,17 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
 	}
 
 	return 0;
+
+out:
+	ndp->active_channel = NULL;
+	ndp->active_package = NULL;
+	if (ndp->flags & NCSI_DEV_RESHUFFLE) {
+		ndp->flags &= ~NCSI_DEV_RESHUFFLE;
+		return ncsi_choose_active_channel(ndp);
+	}
+
+	ncsi_report_link(ndp, false);
+	return -ENODEV;
 }
 
 #if IS_ENABLED(CONFIG_IPV6)
-- 
2.9.0

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

* Re: [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning
  2016-07-21 19:28 [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning Arnd Bergmann
@ 2016-07-22  0:11 ` Gavin Shan
  2016-07-25 17:33 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Gavin Shan @ 2016-07-22  0:11 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: David S. Miller, Gavin Shan, Joel Stanley, netdev, linux-kernel

On Thu, Jul 21, 2016 at 09:28:34PM +0200, Arnd Bergmann wrote:
>gcc-4.9 and higher warn about the newly added NSCI code:
>
>net/ncsi/ncsi-manage.c: In function 'ncsi_process_next_channel':
>net/ncsi/ncsi-manage.c:1003:2: error: 'old_state' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>
>The warning is a false positive and therefore harmless, but it would be good to
>avoid it anyway. I have determined that the barrier in the spin_unlock_irqsave()
>is what confuses gcc to the point that it cannot track whether the variable
>was unused or not.
>
>This rearranges the code in a way that makes it obvious to gcc that old_state
>is always initialized at the time of use, functionally this should not
>change anything.
>
>Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Acked-by: Gavin Shan <gwshan@linux.vnet.ibm.com>

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

* Re: [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning
  2016-07-21 19:28 [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning Arnd Bergmann
  2016-07-22  0:11 ` Gavin Shan
@ 2016-07-25 17:33 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2016-07-25 17:33 UTC (permalink / raw)
  To: arnd; +Cc: gwshan, joel, netdev, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>
Date: Thu, 21 Jul 2016 21:28:34 +0200

> gcc-4.9 and higher warn about the newly added NSCI code:
> 
> net/ncsi/ncsi-manage.c: In function 'ncsi_process_next_channel':
> net/ncsi/ncsi-manage.c:1003:2: error: 'old_state' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> 
> The warning is a false positive and therefore harmless, but it would be good to
> avoid it anyway. I have determined that the barrier in the spin_unlock_irqsave()
> is what confuses gcc to the point that it cannot track whether the variable
> was unused or not.
> 
> This rearranges the code in a way that makes it obvious to gcc that old_state
> is always initialized at the time of use, functionally this should not
> change anything.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Applied.

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

end of thread, other threads:[~2016-07-25 17:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-21 19:28 [PATCH net-next] net/ncsi: avoid maybe-uninitialized warning Arnd Bergmann
2016-07-22  0:11 ` Gavin Shan
2016-07-25 17:33 ` David Miller

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.