From: Rosen Penev <rosenp@gmail.com>
To: netdev@vger.kernel.org
Cc: "Rafał Miłecki" <rafal@milecki.pl>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@kernel.org>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Felix Fietkau" <nbd@openwrt.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net] net: bgmac: fix TX DMA unmapping on fragment mapping failure
Date: Sun, 18 Oct 2026 16:13:48 -0700 [thread overview]
Message-ID: <20261018231348.36884-1-rosenp@gmail.com> (raw)
When mapping a fragment fails, bgmac_dma_tx_add() unwinds with the
wrong slots. It passes the failed fragment's slot->dma_addr, which
holds the mapping error, to dma_unmap_single() for the head. The
fragment loop indexes from ring->end instead of ring->end + 1, so it
unmaps the head a second time as a page and leaves the last mapped
fragment mapped.
None of the affected slots get their dma_addr cleared either, which
includes the head slot when mapping the head fails.
bgmac_dma_tx_ring_free() unmaps every slot with a non-zero dma_addr,
so tearing down the ring unmaps these addresses again.
Unmap the head and each mapped fragment from their own slots, and
clear dma_addr on every slot the failed packet touched.
Fixes: 9cde94506eac ("bgmac: implement scatter/gather support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/ethernet/broadcom/bgmac.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bgmac.c b/drivers/net/ethernet/broadcom/bgmac.c
index 1835266fdd09..134eff89f787 100644
--- a/drivers/net/ethernet/broadcom/bgmac.c
+++ b/drivers/net/ethernet/broadcom/bgmac.c
@@ -208,19 +208,24 @@ static netdev_tx_t bgmac_dma_tx_add(struct bgmac *bgmac,
return NETDEV_TX_OK;
err_dma:
- dma_unmap_single(dma_dev, slot->dma_addr, skb_headlen(skb),
- DMA_TO_DEVICE);
+ slot->dma_addr = 0;
while (i-- > 0) {
- int index = (ring->end + i) % BGMAC_TX_RING_SLOTS;
- struct bgmac_slot_info *slot = &ring->slots[index];
- u32 ctl1 = le32_to_cpu(ring->cpu_base[index].ctl1);
- int len = ctl1 & BGMAC_DESC_CTL1_LEN;
-
- dma_unmap_page(dma_dev, slot->dma_addr, len, DMA_TO_DEVICE);
+ index = (ring->end + 1 + i) % BGMAC_TX_RING_SLOTS;
+ slot = &ring->slots[index];
+ dma_unmap_page(dma_dev, slot->dma_addr,
+ skb_frag_size(&skb_shinfo(skb)->frags[i]),
+ DMA_TO_DEVICE);
+ slot->dma_addr = 0;
}
+ slot = &ring->slots[ring->end % BGMAC_TX_RING_SLOTS];
+ dma_unmap_single(dma_dev, slot->dma_addr, skb_headlen(skb),
+ DMA_TO_DEVICE);
+
err_dma_head:
+ slot->dma_addr = 0;
+
netdev_err(bgmac->net_dev, "Mapping error of skb on ring 0x%X\n",
ring->mmio_base);
--
2.56.0
next reply other threads:[~2026-10-18 23:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 23:13 Rosen Penev [this message]
2026-10-18 23:18 ` [PATCH net] net: bgmac: fix TX DMA unmapping on fragment mapping failure netdev-bot+sinfo
2026-10-18 23:23 ` Rosen Penev
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=20261018231348.36884-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd@openwrt.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafal@milecki.pl \
/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