linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] et131x: Add missing check after DMA map
@ 2025-07-16  9:47 Thomas Fourier
  2025-07-16 11:19 ` mark.einon
  2025-07-18  2:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Fourier @ 2025-07-16  9:47 UTC (permalink / raw)
  Cc: Thomas Fourier, Mark Einon, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Ingo Molnar,
	Thomas Gleixner, netdev, linux-kernel

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")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
---
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(+)

diff --git a/drivers/net/ethernet/agere/et131x.c b/drivers/net/ethernet/agere/et131x.c
index 678eddb36172..5c8217638dda 100644
--- a/drivers/net/ethernet/agere/et131x.c
+++ b/drivers/net/ethernet/agere/et131x.c
@@ -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)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] et131x: Add missing check after DMA map
  2025-07-16  9:47 [PATCH net v2] et131x: Add missing check after DMA map Thomas Fourier
@ 2025-07-16 11:19 ` mark.einon
  2025-07-16 18:53   ` Simon Horman
  2025-07-18  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: mark.einon @ 2025-07-16 11:19 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Ingo Molnar, Thomas Gleixner, netdev, linux-kernel,
	Simon Horman

On Wed, 2025-07-16 at 11:47 +0200, Thomas Fourier 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")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
> 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).

Acked-by: Mark Einon <mark.einon@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] et131x: Add missing check after DMA map
  2025-07-16 11:19 ` mark.einon
@ 2025-07-16 18:53   ` Simon Horman
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2025-07-16 18:53 UTC (permalink / raw)
  To: mark.einon
  Cc: Thomas Fourier, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Ingo Molnar, Thomas Gleixner, netdev,
	linux-kernel

On Wed, Jul 16, 2025 at 12:19:50PM +0100, mark.einon@gmail.com wrote:
> On Wed, 2025-07-16 at 11:47 +0200, Thomas Fourier 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")
> > Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> > ---
> > 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).
> 
> Acked-by: Mark Einon <mark.einon@gmail.com>

Thanks, also LGTM.

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net v2] et131x: Add missing check after DMA map
  2025-07-16  9:47 [PATCH net v2] et131x: Add missing check after DMA map Thomas Fourier
  2025-07-16 11:19 ` mark.einon
@ 2025-07-18  2:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-07-18  2:10 UTC (permalink / raw)
  To: Thomas Fourier
  Cc: mark.einon, andrew+netdev, davem, edumazet, kuba, pabeni, mingo,
	tglx, netdev, linux-kernel

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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")
> Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
> ---
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-07-18  2:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-16  9:47 [PATCH net v2] et131x: Add missing check after DMA map Thomas Fourier
2025-07-16 11:19 ` mark.einon
2025-07-16 18:53   ` Simon Horman
2025-07-18  2:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).