Skip to contentSkip to conversation

net: ag71xx: Add missing check after DMA map

PATCH Applied Thomas Fourier 3 participants 3 messages Jul 16, 2025 – Jul 18, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ag71xx: Add missing check after DMA map

The DMA map functions can fail and should be tested for errors.

Fixes d51b6ce441d3 ("net: ethernet: add ag71xx driver")

---
v1 -> v2:
- do not pass free function to ag71xx_fill_rx_buf()

 drivers/net/ethernet/atheros/ag71xx.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/ethernet/atheros/ag71xx.c +9 -0
index d8e6f23e1432..cbc730c7cff2 100644
@@ -1213,6 +1213,11 @@ static bool ag71xx_fill_rx_buf(struct ag71xx *ag, struct ag71xx_buf *buf,
 	buf->rx.rx_buf = data;
 	buf->rx.dma_addr = dma_map_single(&ag->pdev->dev, data, ag->rx_buf_size,
 					  DMA_FROM_DEVICE);
+	if (dma_mapping_error(&ag->pdev->dev, buf->rx.dma_addr)) {
+		skb_free_frag(data);
+		buf->rx.rx_buf = NULL;
+		return false;
+	}
 	desc->data = (u32)buf->rx.dma_addr + offset;
 	return true;
 }
@@ -1511,6 +1516,10 @@ static netdev_tx_t ag71xx_hard_start_xmit(struct sk_buff *skb,
 
 	dma_addr = dma_map_single(&ag->pdev->dev, skb->data, skb->len,
 				  DMA_TO_DEVICE);
+	if (dma_mapping_error(&ag->pdev->dev, dma_addr)) {
+		netif_dbg(ag, tx_err, ndev, "DMA mapping error\n");
+		goto err_drop;
+	}
 
 	i = ring->curr & ring_mask;
 	desc = ag71xx_ring_desc(ring, i);
Signature · 1 line
2.43.0
#2 lore raw
In reply to Thomas Fourier
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 16 Jul 2025 11:57:25 +0200 you wrote:

The DMA map functions can fail and should be tested for errors.

Fixes d51b6ce441d3 ("net: ethernet: add ag71xx driver")

---
v1 -> v2:
- do not pass free function to ag71xx_fill_rx_buf()

[...]

Here is the summary with links:
- [net,v2] net: ag71xx: Add missing check after DMA map

    https://git.kernel.org/netdev/net-next/c/96a1e15e6021

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html