Skip to contentSkip to conversation

et131x: Add missing check after DMA map

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

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

PATCH v2 1/1 et131x: Add missing check after DMA map

The DMA map functions can fail and should be tested for errors. If the mapping fails, unmap and return an error.

Fixes 38df6492eb51 ("et131x: Add PCIe gigabit ethernet driver et131x to drivers/net")

---
v1 -> v2:
- Fix subject
- Fix double decrement of frag
- Make comment more explicit about why there are two loops

 drivers/net/ethernet/agere/et131x.c | 36 +++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/net/ethernet/agere/et131x.c +36 -0
index 678eddb36172..5c8217638dda 100644
@@ -2459,6 +2459,10 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 							  skb->data,
 							  skb_headlen(skb),
 							  DMA_TO_DEVICE);
+				if (dma_mapping_error(&adapter->pdev->dev,
+						      dma_addr))
+					return -ENOMEM;
+
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
 				frag++;
@@ -2468,6 +2472,10 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 							  skb->data,
 							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
+				if (dma_mapping_error(&adapter->pdev->dev,
+						      dma_addr))
+					return -ENOMEM;
+
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
 				frag++;
@@ -2478,6 +2486,10 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 							  skb_headlen(skb) / 2,
 							  skb_headlen(skb) / 2,
 							  DMA_TO_DEVICE);
+				if (dma_mapping_error(&adapter->pdev->dev,
+						      dma_addr))
+					goto unmap_first_out;
+
 				desc[frag].addr_lo = lower_32_bits(dma_addr);
 				desc[frag].addr_hi = upper_32_bits(dma_addr);
 				frag++;
@@ -2489,6 +2501,9 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 						    0,
 						    desc[frag].len_vlan,
 						    DMA_TO_DEVICE);
+			if (dma_mapping_error(&adapter->pdev->dev, dma_addr))
+				goto unmap_out;
+
 			desc[frag].addr_lo = lower_32_bits(dma_addr);
 			desc[frag].addr_hi = upper_32_bits(dma_addr);
 			frag++;
@@ -2578,6 +2593,27 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
 		       &adapter->regs->global.watchdog_timer);
 	}
 	return 0;
+
+unmap_out:
+	// Unmap the body of the packet with map_page
+	while (--i) {
+		frag--;
+		dma_addr = desc[frag].addr_lo;
+		dma_addr |= (u64)desc[frag].addr_hi << 32;
+		dma_unmap_page(&adapter->pdev->dev, dma_addr,
+			       desc[frag].len_vlan, DMA_TO_DEVICE);
+	}
+
+unmap_first_out:
+	// Unmap the header with map_single
+	while (frag--) {
+		dma_addr = desc[frag].addr_lo;
+		dma_addr |= (u64)desc[frag].addr_hi << 32;
+		dma_unmap_single(&adapter->pdev->dev, dma_addr,
+				 desc[frag].len_vlan, DMA_TO_DEVICE);
+	}
+
+	return -ENOMEM;
 }
 
 static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter)
Signature · 1 line
2.43.0
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 11 lines · Thomas Fourier

The DMA map functions can fail and should be tested for errors. If the mapping fails, unmap and return an error.

Fixes 38df6492eb51 ("et131x: Add PCIe gigabit ethernet driver et131x

to drivers/net")

---
v1 -> v2:
  - Fix subject
  - Fix double decrement of frag
  - Make comment more explicit about why there are two loops

Thanks for the updates Thomas, LGTM (also CC'd Simon who provided the initial comments).

reviewer Reviewed-by
#2 lore raw
Quoted 13 lines · On Wed, Jul 16, 2025 at 12:19:50PM +0100, [email protected] wrote:
Quoted 11 lines · Thomas Fourier

The DMA map functions can fail and should be tested for errors. If the mapping fails, unmap and return an error.

Fixes 38df6492eb51 ("et131x: Add PCIe gigabit ethernet driver et131x

to drivers/net")

---
v1 -> v2:
  - Fix subject
  - Fix double decrement of frag
  - Make comment more explicit about why there are two loops

Quoted 4 lines

Thanks for the updates Thomas, LGTM (also CC'd Simon who provided the initial comments).

Thanks, also LGTM.

#3 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 5 lines · On Wed, 16 Jul 2025 11:47:30 +0200 you wrote:

The DMA map functions can fail and should be tested for errors. If the mapping fails, unmap and return an error.

Fixes 38df6492eb51 ("et131x: Add PCIe gigabit ethernet driver et131x to drivers/net")
Quoted 7 lines

---
v1 -> v2:
- Fix subject
- Fix double decrement of frag
- Make comment more explicit about why there are two loops

[...]

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

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

You are awesome, thank you!

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