drivers: net: xgene: Simplify xgene_enet_setup_mss() to kill warning
PATCH 1/1 drivers: net: xgene: Simplify xgene_enet_setup_mss() to kill warning
With gcc-4.1.2 and -Os:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c: In function ‘xgene_enet_start_xmit’:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c:297: warning: ‘mss_index’ may be used uninitialized in this function
Using a separate variable to track success may confuse the compiler. Preinitialize mss_index with -EBUSY and check for negative error values instead to kill the warning.
---
Compile-tested only.
drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/net/ethernet/apm/xgene/xgene_enet_main.c +3 -10
@@ -293,36 +293,29 @@ static int xgene_enet_tx_completion(struct xgene_enet_desc_ring *cp_ring,static int xgene_enet_setup_mss (struct net_device *ndev,u32 mss) {struct xgene_enet_pdata *pdata =netdev_priv (ndev); -bool mss_index_found = false; -int mss_index; +int mss_index = -EBUSY ;int i;spin_lock (&pdata->mss_lock);/* Reuse the slot if MSS matches */ -for (i =0 ; !mss_index_found && i <NUM_MSS_REG ; i++) { +for (i =0 ; mss_index <0 && i <NUM_MSS_REG ; i++) {if (pdata->mss[i] == mss) { pdata->mss_refcnt[i]++; mss_index = i; - mss_index_found = true; } }/* Overwrite the slot with ref_count = 0 */ -for (i =0 ; !mss_index_found && i <NUM_MSS_REG ; i++) { +for (i =0 ; mss_index <0 && i <NUM_MSS_REG ; i++) {if (!pdata->mss_refcnt[i]) { pdata->mss_refcnt[i]++; pdata->mac_ops->set_mss (pdata, mss, i); pdata->mss[i] = mss; mss_index = i; - mss_index_found = true; } } -/* No slots with ref_count = 0 available, return busy */ -if (!mss_index_found) - mss_index = -EBUSY ; -spin_unlock (&pdata->mss_lock);return mss_index;
Signature · 1 line
2.7.4
From: Geert Uytterhoeven <[email protected]>
Date: Fri, 24 Feb 2017 11:30:03 +0100
Quoted 10 lines
With gcc-4.1.2 and -Os:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c: In function ‘xgene_enet_start_xmit’:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c:297: warning: ‘mss_index’ may be used uninitialized in this functionUsing a separate variable to track success may confuse the compiler. Preinitialize
mss_indexwith-EBUSYand check for negative error values instead to kill the warning.Signed-off-by Geert Uytterhoeven <[email protected]>
Applied, thank you.
Quoted 61 lines · Geert Uytterhoeven
With gcc-4.1.2 and -Os:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c: In function ‘xgene_enet_start_xmit’:
drivers/net/ethernet/apm/xgene/xgene_enet_main.c:297: warning: ‘mss_index’ may be used uninitialized in this functionUsing a separate variable to track success may confuse the compiler. Preinitialize
mss_indexwith-EBUSYand check for negative error values instead to kill the warning.Signed-off-by Geert Uytterhoeven <[email protected]>---
Compile-tested only.drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)drivers/net/ethernet/apm/xgene/xgene_enet_main.c +3
-11@@ -293,36 +293,29 @@ static int xgene_enet_tx_completion(struct xgene_enet_desc_ring *cp_ring,static int xgene_enet_setup_mss (struct net_device *ndev,u32 mss) {struct xgene_enet_pdata *pdata =netdev_priv (ndev); -bool mss_index_found = false; -int mss_index; +int mss_index = -EBUSY ;int i;spin_lock (&pdata->mss_lock);/* Reuse the slot if MSS matches */ -for (i =0 ; !mss_index_found && i <NUM_MSS_REG ; i++) { +for (i =0 ; mss_index <0 && i <NUM_MSS_REG ; i++) {if (pdata->mss[i] == mss) { pdata->mss_refcnt[i]++; mss_index = i; - mss_index_found = true; } }/* Overwrite the slot with ref_count = 0 */ -for (i =0 ; !mss_index_found && i <NUM_MSS_REG ; i++) { +for (i =0 ; mss_index <0 && i <NUM_MSS_REG ; i++) {if (!pdata->mss_refcnt[i]) { pdata->mss_refcnt[i]++; pdata->mac_ops->set_mss (pdata, mss, i); pdata->mss[i] = mss; mss_index = i; - mss_index_found = true; } } -/* No slots with ref_count = 0 available, return busy */ -if (!mss_index_found) - mss_index = -EBUSY ; -spin_unlock (&pdata->mss_lock);return mss_index; --
Quoted 2 lines
2.7.4
Thanks.