Skip to contentSkip to conversation

net: dlink: handle dma_map_single() failure properly

PATCH Applied Yeounsu Moon 3 participants 4 messages Oct 9, 2025 – Oct 12, 2025

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

PATCH v2 1/1 net: dlink: handle dma_map_single() failure properly

There is no error handling for dma_map_single() failures.

Add error handling by checking dma_mapping_error() and freeing the skb using dev_kfree_skb() (process context) when it fails.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested-on: D-Link DGE-550T Rev-A3

---
Changelog:
v2:
- fix one thing properly
- use goto statement, per Simon's suggestion
v1: https://lore.kernel.org/netdev/[email protected]/

---
 drivers/net/ethernet/dlink/dl2k.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)
drivers/net/ethernet/dlink/dl2k.c +16 -7
index 1996d2e4e3e2..7077d705e471 100644
@@ -508,25 +508,34 @@ static int alloc_list(struct net_device *dev)
 	for (i = 0; i < RX_RING_SIZE; i++) {
 		/* Allocated fixed size of skbuff */
 		struct sk_buff *skb;
+		dma_addr_t addr;
 
 		skb = netdev_alloc_skb_ip_align(dev, np->rx_buf_sz);
 		np->rx_skbuff[i] = skb;
-		if (!skb) {
-			free_list(dev);
-			return -ENOMEM;
-		}
+		if (!skb)
+			goto err_free_list;
+
+		addr = dma_map_single(&np->pdev->dev, skb->data,
+				      np->rx_buf_sz, DMA_FROM_DEVICE);
+		if (dma_mapping_error(&np->pdev->dev, addr))
+			goto err_kfree_skb;
 
 		np->rx_ring[i].next_desc = cpu_to_le64(np->rx_ring_dma +
 						((i + 1) % RX_RING_SIZE) *
 						sizeof(struct netdev_desc));
 		/* Rubicon now supports 40 bits of addressing space. */
-		np->rx_ring[i].fraginfo =
-		    cpu_to_le64(dma_map_single(&np->pdev->dev, skb->data,
-					       np->rx_buf_sz, DMA_FROM_DEVICE));
+		np->rx_ring[i].fraginfo = cpu_to_le64(addr);
 		np->rx_ring[i].fraginfo |= cpu_to_le64((u64)np->rx_buf_sz << 48);
 	}
 
 	return 0;
+
+err_kfree_skb:
+	dev_kfree_skb(np->rx_skbuff[i]);
+	np->rx_skbuff[i] = NULL;
+err_free_list:
+	free_list(dev);
+	return -ENOMEM;
 }
 
 static void rio_hw_init(struct net_device *dev)
Signature · 1 line
2.51.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Yeounsu Moon

There is no error handling for dma_map_single() failures.

Add error handling by checking dma_mapping_error() and freeing the skb using dev_kfree_skb() (process context) when it fails.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested-on: D-Link DGE-550T Rev-A3

FWIIW, I don't think my Suggested-by tag is strictly necessary here. I did suggest an implementation approach. And I'm very happy that you took my idea on board. But I'd view as more of a tweak in this case. Because the overall meaning of the patch remains the same as your original version.

Quoted 6 lines

---
Changelog:
v2:
- fix one thing properly
- use goto statement, per Simon's suggestion
v1: https://lore.kernel.org/netdev/[email protected]/

Thanks for the update, this version looks good to me.

#2 lore raw
Quoted 11 lines · Simon Horman
Quoted 9 lines · Yeounsu Moon

There is no error handling for dma_map_single() failures.

Add error handling by checking dma_mapping_error() and freeing the skb using dev_kfree_skb() (process context) when it fails.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested-on: D-Link DGE-550T Rev-A3

Quoted 5 lines

FWIIW, I don't think my Suggested-by tag is strictly necessary here. I did suggest an implementation approach. And I'm very happy that you took my idea on board. But I'd view as more of a tweak in this case. Because the overall meaning of the patch remains the same as your original version.

Thank you for letting me know,

Quoted 10 lines
Quoted 6 lines

---
Changelog:
v2:
- fix one thing properly
- use goto statement, per Simon's suggestion
v1: https://lore.kernel.org/netdev/[email protected]/

Thanks for the update, this version looks good to me.

And I really appreciate your review.

#3 lore raw
In reply to Yeounsu Moon
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

Quoted 11 lines · On Fri, 10 Oct 2025 00:57:16 +0900 you wrote:

There is no error handling for dma_map_single() failures.

Add error handling by checking dma_mapping_error() and freeing the skb using dev_kfree_skb() (process context) when it fails.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

Tested-on: D-Link DGE-550T Rev-A3

[...]

Here is the summary with links:
- [net,v2] net: dlink: handle dma_map_single() failure properly

    https://git.kernel.org/netdev/net/c/65946eac6d88

You are awesome, thank you!

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