From: Simon Horman <horms@kernel.org>
To: netdev-bot+sashiko@kernel.org
Cc: bhargava.marreddy@broadcom.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
andrew+netdev@lunn.ch, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, michael.chan@broadcom.com,
pavan.chebbi@broadcom.com, vsrama-krishna.nemani@broadcom.com,
vikas.gupta@broadcom.com, dharmender.garg@broadcom.com
Subject: Re: [PATCH net-next v2 1/6] bnge: Extract bnapi allocation and cleanup into helpers
Date: Sat, 26 Sep 2026 19:49:26 +0100 [thread overview]
Message-ID: <20260926184926.GC13925@horms.kernel.org> (raw)
In-Reply-To: <179026966721.2160803.3672240762098051468@kernel.org>
On Thu, Sep 24, 2026 at 05:07:47PM +0000, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
>
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
In the interest of moving things along I will respond to this.
>
> - [Medium] The commit message describes the three new NULL guards as
> preparatory hardening ("add NULL guards for rx_ring and tx_ring in…
>
> --
>
> bnge: Extract bnapi allocation and cleanup into helpers
>
> This moves the bn->bnapi allocation and free code out of
> bnge_alloc_core()/bnge_free_core() into bnge_alloc_bnapi_mem() and
> bnge_free_bnapi_mem(), and adds NULL checks for bn->rx_ring and
> bn->tx_ring in the ring cleanup helpers.
>
> > diff --git a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > index a4288f0258f87..c1810a3098883 100644
> > --- a/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > +++ b/drivers/net/ethernet/broadcom/bnge/bnge_netdev.c
> > @@ -825,6 +825,9 @@ static void bnge_free_tpa_info(struct bnge_net *bn)
> > struct bnge_dev *bd = bn->bd;
> > int i, j;
> >
> > + if (!bn->rx_ring)
> > + return;
> > +
The check above appears to be purely defensive.
I do not believe it can ever be true.
If so, please remove it.
> > for (i = 0; i < bd->rx_nr_rings; i++) {
> > struct bnge_rx_ring_info *rxr = &bn->rx_ring[i];
> >
> > @@ -881,6 +884,9 @@ static void bnge_free_rx_rings(struct bnge_net *bn)
> > struct bnge_dev *bd = bn->bd;
> > int i;
> >
> > + if (!bn->rx_ring)
> > + return;
> > +
> > bnge_free_tpa_info(bn);
> > for (i = 0; i < bd->rx_nr_rings; i++) {
> > struct bnge_rx_ring_info *rxr = &bn->rx_ring[i];
> > @@ -1024,6 +1030,9 @@ static void bnge_free_tx_rings(struct bnge_net *bn)
> > struct bnge_dev *bd = bn->bd;
> > int i;
> >
> > + if (!bn->tx_ring)
> > + return;
> > +
>
> [Severity: Medium]
> Are these three new NULL checks really just preparation, or do they fix a
> reachable NULL pointer dereference that exists today?
It seems to me that the two hunks above do fix a bug,
can could manifest under memory pressure..
And thus should be broken out as a separate patch for net.
>
> The commit message says only:
>
> Prepare the driver to move bnapi allocation out of the open/close path,
> and add NULL guards for rx_ring and tx_ring in core driver cleanup paths.
>
> Before this patch, bnge_alloc_core() allocates bn->bnapi, then bn->rx_ring,
> then bn->tx_ring, and every failure goes to err_free_core: which calls
> bnge_free_core(). bnge_free_core() unconditionally calls
> bnge_free_tx_rings() and bnge_free_rx_rings(), so if the bn->rx_ring
> allocation fails both pointers are still NULL:
>
> drivers/net/ethernet/broadcom/bnge/bnge_netdev.c:bnge_free_tx_rings() {
> for (i = 0; i < bd->tx_nr_rings; i++) {
> struct bnge_tx_ring_info *txr = &bn->tx_ring[i];
> ...
> bnge_free_ring(bd, &ring->ring_mem);
> }
>
> and bnge_free_ring() dereferences that near-NULL address right away:
>
> drivers/net/ethernet/broadcom/bnge/bnge_rmem.c:bnge_free_ring() {
> if (!rmem->pg_arr)
> goto skip_pages;
>
> The rx side looks the same: bnge_free_rx_rings() -> bnge_free_tpa_info()
> reads rxr->rx_tpa_idx_map, and bnge_free_rx_rings() itself calls
> page_pool_destroy(rxr->page_pool), both off a NULL bn->rx_ring.
>
> Since bnge_alloc_core() runs from the ndo_open path, an allocation failure
> during "ip link set dev ethX up" would oops instead of returning -ENOMEM.
> git blame points the affected loops at commit 0259379037cab9 ("bng_en: Add
> initial support for RX and TX rings"). Would it make sense to split these
> guards into their own patch with a Fixes: 0259379037cab9 tag, so it can be
> picked up for stable? No commit in this series (10cfa109c8..63494c308b19)
> carries such a tag or mentions the crash.
>
> Note that bnge_free_rx_ring_pair_bufs() already had the same
> if (!bn->rx_ring) return; check, which suggests the guard is functional
> rather than cosmetic.
>
> > for (i = 0; i < bd->tx_nr_rings; i++) {
> > struct bnge_tx_ring_info *txr = &bn->tx_ring[i];
> > struct bnge_ring_struct *ring;
>
> [ ... ]
>
> > @@ -1241,6 +1254,19 @@ static int bnge_alloc_core(struct bnge_net *bn)
> > nqr->ring_struct.ring_mem.flags = BNGE_RMEM_RING_PTE_FLAG;
> > }
> >
> > + return 0;
> > +}
> > +
> > +static int bnge_alloc_core(struct bnge_net *bn)
> > +{
> > + struct bnge_dev *bd = bn->bd;
> > + int i, j, rc;
> > +
> > + rc = bnge_alloc_bnapi_mem(bn);
> > + if (rc)
> > + return rc;
> > +
> > + rc = -ENOMEM;
> > bn->rx_ring = kzalloc_objs(struct bnge_rx_ring_info, bd->rx_nr_rings);
> > if (!bn->rx_ring)
> > goto err_free_core;
>
> This is the branch that reaches bnge_free_core() with both bn->rx_ring and
> bn->tx_ring still NULL.
I will add that they way that this code relies on unwind functions,
such as bnge_free_core(), that can unwind from both a fully and partially
initialised state is not the preferred approach.
E.g. while having bnge_free_core() fully clean up state the taredown
patch is fine, the probe path should have a goto ladder that unwinds
incrementally based on where initialization failed.
For a bug fix, a minimal approach, that adds some conditions, is probably
best. But perhaps there are more cases than are covered by this discussion.
--
pw-bot: changes-requested
next prev parent reply other threads:[~2026-09-26 18:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 5:28 [PATCH net-next v2 0/6] bnge: Support async events while down Bhargava Marreddy
2026-09-22 5:28 ` [PATCH net-next v2 1/6] bnge: Extract bnapi allocation and cleanup into helpers Bhargava Marreddy
2026-09-24 17:07 ` netdev-bot+sashiko
2026-09-26 18:49 ` Simon Horman [this message]
2026-09-22 5:29 ` [PATCH net-next v2 2/6] bnge: Extract per-NQ ring allocation and init helpers Bhargava Marreddy
2026-09-22 5:29 ` [PATCH net-next v2 3/6] bnge: Move bnapi and ring_grp allocation to probe/remove Bhargava Marreddy
2026-09-22 5:29 ` [PATCH net-next v2 4/6] bnge: Drop obsolete bn->bnapi NULL checks in open/close paths Bhargava Marreddy
2026-09-22 5:29 ` [PATCH net-next v2 5/6] bnge: Quiesce NQ0 around ring teardown in bnge_free_core() Bhargava Marreddy
2026-09-22 5:29 ` [PATCH net-next v2 6/6] bnge: Create NQ0 during probe and keep active across open/close Bhargava Marreddy
2026-09-24 17:07 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260926184926.GC13925@horms.kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bhargava.marreddy@broadcom.com \
--cc=davem@davemloft.net \
--cc=dharmender.garg@broadcom.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.chan@broadcom.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pavan.chebbi@broadcom.com \
--cc=vikas.gupta@broadcom.com \
--cc=vsrama-krishna.nemani@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®