Re: [PATCH net-next v5 3/5] bnge: add bnge_for_each_open_nq() iterator

From: Bhargava Chenna Marreddy

Date: Fri Nov 20 2026 - 06:19:00 EST


Responding to Sashiko comments:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117061641.122942-1-bhargava.marreddy%40broadcom.com

On Tue, Nov 17, 2026 at 11:48 AM Bhargava Marreddy
<bhargava.marreddy@xxxxxxxxxxxx> wrote:
> @@ -1255,10 +1255,11 @@ static int bnge_alloc_core(struct bnge_net *bn)
>
> bn->bnapi = bnapi;
> bnapi += arr_size;
> - for (i = 0; i < bd->nq_nr_rings; i++, bnapi += size) {
> + bnge_for_each_open_nq(i, bd) {
> bn->bnapi[i] = bnapi;
> bn->bnapi[i]->index = i;
> bn->bnapi[i]->bn = bn;
> + bnapi += size;
> }

Sashiko:
Discovered by: fable-5-1, opus-5-5 · Missed by: sashiko-gemini
With BNGE_FIRST_OPEN_NQ at 0, this loop does the same thing as the old
one. Two things around it have not changed:
- The kzalloc() above is still sized for all bd->nq_nr_rings bnapi
structs.
- Several unconverted loops still dereference bn->bnapi[i] starting
from index 0. Examples are the rx_ring setup just below,
bnge_disable_napi(), and the cp ring free loop in
bnge_hwrm_ring_free().
Here is the rx_ring setup:
for (i = 0; i < bd->rx_nr_rings; i++) {
...
rxr->bnapi = bn->bnapi[i];
bn->bnapi[i]->rx_ring = &bn->rx_ring[i];
}
If BNGE_FIRST_OPEN_NQ were raised with nothing else changed, would
bn->bnapi[0..BNGE_FIRST_OPEN_NQ-1] stay NULL, so that these loops
dereference a NULL pointer?
Nothing changes at runtime in this patch. The last patch in the series,
"bnge: create NQ0 during probe and keep it active across open/close",
sets the define to 1. In the same change it adds
bn->bnapi[0] = bn->nq0 and sizes the allocation as
size * (bd->nq_nr_rings - BNGE_FIRST_OPEN_NQ). So no commit in the
series seems to reach the NULL case.

Response:
That is harmless in this patch. BNGE_FIRST_OPEN_NQ is 0 here, so
bnapi[0..FIRST-1] is an empty range and there is no NULL entry to hit.

The define becomes 1 only in patch 5/5. The same patch sets
bn->bnapi[0] = bn->nq0 and sizes the allocation as
size * (nq_nr_rings - BNGE_FIRST_OPEN_NQ). No commit in the series has
a non-zero define with a NULL bnapi[0], so bisectability is preserved.

>
> bn->rx_ring = kzalloc_objs(struct bnge_rx_ring_info, bd->rx_nr_rings);
> @@ -1976,7 +1977,7 @@ static int bnge_hwrm_ring_alloc(struct bnge_net *bn)
> int i, rc = 0;
>
> agg_rings = !!(bnge_is_agg_reqd(bd));
> - for (i = 0; i < bd->nq_nr_rings; i++) {
> + bnge_for_each_open_nq(i, bd) {
> struct bnge_napi *bnapi = bn->bnapi[i];
> struct bnge_ring_struct *ring = &bnapi->nq_ring.ring_struct;
Sashiko:
Discovered by: fable-5-1, opus-5-5 · Missed by: sashiko-gemini
The body of this loop still chooses the async event completion ring by a
hardcoded index:
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c:bnge_hwrm_ring_alloc() {
...
if (!i) {
rc = bnge_hwrm_set_async_event_cr(bd, ring->fw_ring_id);
if (rc)
netdev_warn(bn->netdev, "Failed to set async event completion ring.\n");
}
...
}
Once BNGE_FIRST_OPEN_NQ is above 0, i never equals 0 in this loop. Would
bnge_hwrm_set_async_event_cr() then never be called from here?
With the define at 0 there is no change in behavior. The final patch of
the series ("bnge: create NQ0 during probe and keep it active across
open/close") removes this block. It calls bnge_hwrm_set_async_event_cr()
from the probe-time NQ0 setup instead, guarded by
BUILD_BUG_ON(BNGE_FIRST_OPEN_NQ != 1). As far as I can tell, no commit in
the series has both a non-zero BNGE_FIRST_OPEN_NQ and this if (!i) block.

Response:
Same situation. With the define at 0, i == 0 is still the first NQ in
the loop, so behavior is unchanged.

Patch 5/5 removes the if (!i) block and moves the
bnge_hwrm_set_async_event_cr() call to the probe-time NQ0 setup,
guarded by BUILD_BUG_ON(BNGE_FIRST_OPEN_NQ != 1). No commit in the
series has both a non-zero define and the if (!i) check, so
bisectability is intact.

Since patch 5/5 resolves both points, I believe no change is needed
in this series.

Thanks,
Bhargava Marreddy

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature