Skip to content

Commit a1b43ed

Browse files
arndbdavem330
authored andcommitted
net/ncsi: avoid maybe-uninitialized warning
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> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 974b996 commit a1b43ed

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

‎net/ncsi/ncsi-manage.c‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -982,23 +982,18 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
982982
spin_lock_irqsave(&ndp->lock, flags);
983983
nc = list_first_or_null_rcu(&ndp->channel_queue,
984984
struct ncsi_channel, link);
985-
if (nc) {
986-
old_state = xchg(&nc->state, NCSI_CHANNEL_INVISIBLE);
987-
list_del_init(&nc->link);
985+
if (!nc) {
986+
spin_unlock_irqrestore(&ndp->lock, flags);
987+
goto out;
988988
}
989+
990+
old_state = xchg(&nc->state, NCSI_CHANNEL_INVISIBLE);
991+
list_del_init(&nc->link);
992+
989993
spin_unlock_irqrestore(&ndp->lock, flags);
990994

991995
ndp->active_channel = nc;
992-
ndp->active_package = nc ? nc->package : NULL;
993-
if (!nc) {
994-
if (ndp->flags & NCSI_DEV_RESHUFFLE) {
995-
ndp->flags &= ~NCSI_DEV_RESHUFFLE;
996-
return ncsi_choose_active_channel(ndp);
997-
}
998-
999-
ncsi_report_link(ndp, false);
1000-
return -ENODEV;
1001-
}
996+
ndp->active_package = nc->package;
1002997

1003998
switch (old_state) {
1004999
case NCSI_CHANNEL_INACTIVE:
@@ -1017,6 +1012,17 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
10171012
}
10181013

10191014
return 0;
1015+
1016+
out:
1017+
ndp->active_channel = NULL;
1018+
ndp->active_package = NULL;
1019+
if (ndp->flags & NCSI_DEV_RESHUFFLE) {
1020+
ndp->flags &= ~NCSI_DEV_RESHUFFLE;
1021+
return ncsi_choose_active_channel(ndp);
1022+
}
1023+
1024+
ncsi_report_link(ndp, false);
1025+
return -ENODEV;
10201026
}
10211027

10221028
#if IS_ENABLED(CONFIG_IPV6)

0 commit comments

Comments
 (0)