net/bnxt: shadow variable warnings
cover net/bnxt: shadow variable warnings
This allows bnxt driver to build cleanly with -Wshadow. Part of a larger effort to globally enable shadow warning.
Stephen Hemminger (2):
eal: add RTE_MIN4 and RTE_MAX4 macros
net/bnxt: fix shadow variable warnings
drivers/net/bnxt/bnxt.h | 6 +++--- drivers/net/bnxt/bnxt_ethdev.c | 3 +-- drivers/net/bnxt/bnxt_rxq.c | 6 ++---- drivers/net/bnxt/bnxt_txr.c | 3 --- lib/eal/include/rte_common.h | 20 ++++++++++++++++++++ 5 files changed, 26 insertions(+), 12 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/2 eal: add RTE_MIN4 and RTE_MAX4 macros
These are analogous to the existing RTE_MIN3 macros and allow drivers to take compute minimum of four values without invoking the shadow warning gods.
--- lib/eal/include/rte_common.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
lib/eal/include/rte_common.h +20 -0
@@ -812,6 +812,16 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; (_b_min3 < _c_min3 ? _b_min3 : _c_min3); \ }) +/** +* Macro to return the minimum of four numbers +*/ +#define RTE_MIN4 (a, b, c, d) \ + __extension__ ({ \ + typeof (a) _min4_ab = RTE_MIN((a), (b)); \ + typeof (c) _min4_cd = RTE_MIN((c), (d)); \ + RTE_MIN(_min4_ab, _min4_cd); \ + }) +/** * Macro to return the minimum of two numbers *
@@ -845,6 +855,16 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; (_b_max3 > _c_max3 ? _b_max3 : _c_max3); \ }) +/** +* Macro to return the maximum of four numbers +*/ +#define RTE_MAX4 (a, b, c, d) \ + __extension__ ({ \ + typeof (a) _max4_ab = RTE_MAX((a), (b)); \ + typeof (c) _max4_cd = RTE_MAX((c), (d)); \ + RTE_MAX(_max4_ab, _max4_cd); \ + }) +/** * Macro to return the maximum of two numbers *
Signature · 1 line
2.51.0
PATCH 2/2 net/bnxt: fix shadow variable warnings
In reply to Stephen HemmingerFix things flagged as warnings about shadowed variables. If the variable was harmless overlap then just drop the shadowed version. For min values case use RTE_MIN3() and RTE_MIN4().
--- drivers/net/bnxt/bnxt.h | 6 +++--- drivers/net/bnxt/bnxt_ethdev.c | 3 +-- drivers/net/bnxt/bnxt_rxq.c | 6 ++---- drivers/net/bnxt/bnxt_txr.c | 3 --- 4 files changed, 6 insertions(+), 12 deletions(-)
drivers/net/bnxt/bnxt.h +3 -3
@@ -1110,9 +1110,9 @@ inline uint16_t bnxt_max_rings(struct bnxt *bp)* max Tx rings == max Rx rings, one stat ctx for each. */ if (BNXT_STINGRAY (bp)) { - max_rx_rings =RTE_MIN (RTE_MIN (max_rx_rings /2U , -MAX_STINGRAY_RINGS ), - bp->max_stat_ctx /2U ); + max_rx_rings =RTE_MIN3 (max_rx_rings /2U , +MAX_STINGRAY_RINGS , + bp->max_stat_ctx /2U ); }else { max_rx_rings =RTE_MIN (max_rx_rings /2U , bp->max_stat_ctx /2U );
drivers/net/bnxt/bnxt_ethdev.c +1 -2
@@ -473,7 +473,7 @@ static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)/* Alloc RSS context only if RSS mode is enabled */ if (dev_conf->rxmode.mq_mode &RTE_ETH_MQ_RX_RSS ) { -int j, nr_ctxs =bnxt_rss_ctxts (bp); +unsigned int nr_ctxs =bnxt_rss_ctxts (bp);/* RSS table size in P5 is 512. * Cap max Rx rings to same value
@@ -3560,7 +3560,6 @@ bnxt_rx_descriptor_status_op(void *rx_queue, uint16_t offset)*/ #if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 )if (bp->flags &BNXT_FLAG_RX_VECTOR_PKT_MODE ) { -struct rx_pkt_cmpl *rxcmp;uint32_t cons;/* Check status of completion descriptor. */
drivers/net/bnxt/bnxt_rxq.c +2 -4
@@ -98,10 +98,8 @@ int bnxt_mq_rx_configure(struct bnxt *bp)/* ETH_8/64_POOLs */ pools = conf->nb_queue_pools;/* For each pool, allocate MACVLAN CFA rule & VNIC */ - max_pools =RTE_MIN (bp->max_vnics, -RTE_MIN (bp->max_l2_ctx, -RTE_MIN (bp->max_rsscos_ctx, -RTE_ETH_64_POOLS ))); + max_pools =RTE_MIN4 (bp->max_vnics, bp->max_l2_ctx, + bp->max_rsscos_ctx,RTE_ETH_64_POOLS );PMD_DRV_LOG_LINE (DEBUG ,"pools = %u max_pools = %u" , pools, max_pools);
drivers/net/bnxt/bnxt_txr.c +0 -3
@@ -179,9 +179,6 @@ bnxt_check_pkt_needs_ts(struct rte_mbuf *m)if (proto ==RTE_ETHER_TYPE_ECPRI )return true;if (proto ==RTE_ETHER_TYPE_VLAN ) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; - vh =rte_pktmbuf_read (m, off,sizeof (*vh), &vh_copy);if (unlikely (vh ==NULL ))return false;
Signature · 1 line
2.51.0
Re: [PATCH 2/2] net/bnxt: fix shadow variable warnings
Quoted 7 lines · Stephen Hemminger
Fix things flagged as warnings about shadowed variables. If the variable was harmless overlap then just drop the shadowed version. For min values case use
RTE_MIN3()andRTE_MIN4().Signed-off-by Stephen Hemminger <[email protected]>---
Quoted 85 lines
drivers/net/bnxt/bnxt.h | 6 +++--- drivers/net/bnxt/bnxt_ethdev.c | 3 +-- drivers/net/bnxt/bnxt_rxq.c | 6 ++---- drivers/net/bnxt/bnxt_txr.c | 3 --- 4 files changed, 6 insertions(+), 12 deletions(-)drivers/net/bnxt/bnxt.h +3
-3@@ -1110,9 +1110,9 @@ inline uint16_t bnxt_max_rings(struct bnxt *bp)* max Tx rings == max Rx rings, one stat ctx for each. */ if (BNXT_STINGRAY (bp)) { - max_rx_rings =RTE_MIN (RTE_MIN (max_rx_rings /2U , -MAX_STINGRAY_RINGS ), - bp->max_stat_ctx /2U ); + max_rx_rings =RTE_MIN3 (max_rx_rings /2U , +MAX_STINGRAY_RINGS , + bp->max_stat_ctx /2U ); }else { max_rx_rings =RTE_MIN (max_rx_rings /2U , bp->max_stat_ctx /2U );drivers/net/bnxt/bnxt_ethdev.c +1
-1@@ -473,7 +473,7 @@ static int bnxt_setup_one_vnic(struct bnxt *bp, uint16_t vnic_id)/* Alloc RSS context only if RSS mode is enabled */ if (dev_conf->rxmode.mq_mode &RTE_ETH_MQ_RX_RSS ) { -int j, nr_ctxs =bnxt_rss_ctxts (bp); +unsigned int nr_ctxs =bnxt_rss_ctxts (bp);/* RSS table size in P5 is 512. * Cap max Rx rings to same value
drivers/net/bnxt/bnxt_ethdev.c +0
-1@@ -3560,7 +3560,6 @@ bnxt_rx_descriptor_status_op(void *rx_queue,uint16_t offset) */ #if defined(RTE_ARCH_X86 ) || defined(RTE_ARCH_ARM64 )if (bp->flags &BNXT_FLAG_RX_VECTOR_PKT_MODE ) { -struct rx_pkt_cmpl *rxcmp;uint32_t cons;/* Check status of completion descriptor. */drivers/net/bnxt/bnxt_rxq.c +2
-4@@ -98,10 +98,8 @@ int bnxt_mq_rx_configure(struct bnxt *bp)/* ETH_8/64_POOLs */ pools = conf->nb_queue_pools;/* For each pool, allocate MACVLAN CFA rule & VNIC */ - max_pools =RTE_MIN (bp->max_vnics, -RTE_MIN (bp->max_l2_ctx, -RTE_MIN (bp->max_rsscos_ctx, -RTE_ETH_64_POOLS ))); + max_pools =RTE_MIN4 (bp->max_vnics, bp->max_l2_ctx, + bp->max_rsscos_ctx,RTE_ETH_64_POOLS ); PMD_DRV_LOG_LINE(DEBUG,"pools = %u max_pools = %u", pools, max_pools);drivers/net/bnxt/bnxt_txr.c +0
-3@@ -179,9 +179,6 @@ bnxt_check_pkt_needs_ts(struct rte_mbuf *m)if (proto ==RTE_ETHER_TYPE_ECPRI )return true;if (proto ==RTE_ETHER_TYPE_VLAN ) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; - vh =rte_pktmbuf_read (m, off,sizeof (*vh), &vh_copy);if (unlikely (vh ==NULL ))return false;--
2.51.0
Re: [PATCH 2/2] net/bnxt: fix shadow variable warnings
In reply to Stephen Hemminger12/03/2026 01:20, Stephen Hemminger:
Quoted 11 lines
Fix things flagged as warnings about shadowed variables. If the variable was harmless overlap then just drop the shadowed version. For min values case use
RTE_MIN3()andRTE_MIN4().Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/bnxt/bnxt.h | 6 +++--- drivers/net/bnxt/bnxt_ethdev.c | 3 +-- drivers/net/bnxt/bnxt_rxq.c | 6 ++---- drivers/net/bnxt/bnxt_txr.c | 3 --- 4 files changed, 6 insertions(+), 12 deletions(-)
Why not removing cflags += no_shadow_cflag ?
Re: [PATCH 2/2] net/bnxt: fix shadow variable warnings
Quoted 13 lines · On Tue, 17 Mar 2026 09:02:45 +0100 Thomas Monjalon <[email protected]> wrote:
12/03/2026 01:20, Stephen Hemminger:
Quoted 11 lines
Fix things flagged as warnings about shadowed variables. If the variable was harmless overlap then just drop the shadowed version. For min values case use
RTE_MIN3()andRTE_MIN4().Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/bnxt/bnxt.h | 6 +++--- drivers/net/bnxt/bnxt_ethdev.c | 3 +-- drivers/net/bnxt/bnxt_rxq.c | 6 ++---- drivers/net/bnxt/bnxt_txr.c | 3 --- 4 files changed, 6 insertions(+), 12 deletions(-)
Quoted 3 lines
Why not removing cflags +=
no_shadow_cflag?
Yes, should do that, just wasn't on the tree I was testing.