Skip to contentSkip to conversation

net: sxgbe: fix descriptor ring allocation failure handling

PATCH Applied Chenguang Zhao 4 participants 7 messages Jul 23 – Jul 29

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

v3 cover net: sxgbe: fix descriptor ring allocation failure handling

From: Chenguang Zhao <[email protected]>

init_dma_desc_rings() leaks already-allocated TX rings when RX allocation fails, and sxgbe_open() ignores its return value and continues with invalid DMA rings. Fix the cleanup path and check the error.

Patch 1 frees TX rings on RX allocation failure.
Patch 2 makes sxgbe_open() handle init_dma_desc_rings() failure.

Chenguang Zhao (2):
net: sxgbe: free TX rings on RX allocation failure
net: sxgbe: check descriptor ring allocation failures

 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

---
v3:
- Patch 1: Per Vadim’s suggestion, reuse the existing code for cleaning up Tx rings

v2:
https://lore.kernel.org/all/[email protected]/

v1:
https://lore.kernel.org/all/[email protected]/

Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/2 net: sxgbe: free TX rings on RX allocation failure

From: Chenguang Zhao <[email protected]>

When RX descriptor ring allocation fails, init_dma_desc_rings() only frees the partially allocated RX rings and returns. The TX rings that were allocated earlier in the same function are leaked.

Rearrange error labels to clean up TX rings upon RX failures.

Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
---
 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +4 -5
index 5051ada43d2f..9b48a587d5c2 100644
@@ -597,14 +597,13 @@ static int init_dma_desc_rings(struct net_device *netd)
 
 	return 0;
 
-txalloc_err:
-	while (queue_num--)
-		free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize);
-	return ret;
-
 rxalloc_err:
 	while (queue_num--)
 		free_rx_ring(priv->device, priv->rxq[queue_num], rx_rsize);
+	queue_num = SXGBE_TX_QUEUES;
+txalloc_err:
+	while (queue_num--)
+		free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize);
 	return ret;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v3 1/2
#2 lore raw

Re: [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure

Quoted 27 lines · Chenguang Zhao

From: Chenguang Zhao <[email protected]>

When RX descriptor ring allocation fails, init_dma_desc_rings() only frees the partially allocated RX rings and returns. The TX rings that were allocated earlier in the same function are leaked.

Rearrange error labels to clean up TX rings upon RX failures.

Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
---
  drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 9 ++++-----
  1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +0 -5
index 5051ada43d2f..9b48a587d5c2 100644
@@ -597,14 +597,13 @@ static int init_dma_desc_rings(struct net_device *netd)
 
  	return 0;
 
-txalloc_err:
-	while (queue_num--)
-		free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize);
-	return ret;
-

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int init_dma_desc_rings(struct net_device *netd) · line 609

Quoted 10 lines
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +4 -0
  rxalloc_err:
  	while (queue_num--)
  		free_rx_ring(priv->device, priv->rxq[queue_num], rx_rsize);
+	queue_num = SXGBE_TX_QUEUES;
+txalloc_err:
+	while (queue_num--)
+		free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize);
  	return ret;
  }
 
#3 lore raw

PATCH v3 2/2 net: sxgbe: check descriptor ring allocation failures

In reply to Chenguang Zhao

From: Chenguang Zhao <[email protected]>

sxgbe_open() ignores the return value of init_dma_desc_rings() and continues to program DMA with invalid ring addresses when allocation fails. Check the return value and disconnect the PHY on failure.

Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
---
 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +4 -1
index 9b48a587d5c2..70cf3619555f 100644
@@ -1078,7 +1078,9 @@ static int sxgbe_open(struct net_device *dev)
 	priv->dma_buf_sz = SXGBE_ALIGN(DMA_BUFFER_SIZE);
 	priv->tx_tc = TC_DEFAULT;
 	priv->rx_tc = TC_DEFAULT;
-	init_dma_desc_rings(dev);
+	ret = init_dma_desc_rings(dev);
+	if (ret)
+		goto init_phy_error;
 
 	/* DMA initialization and SW reset */
 	ret = sxgbe_init_dma_engine(priv);
@@ -1187,6 +1189,7 @@ static int sxgbe_open(struct net_device *dev)
 
 init_error:
 	free_dma_desc_resources(priv);
+init_phy_error:
 	if (dev->phydev)
 		phy_disconnect(dev->phydev);
 phy_error:
Signature · 1 line
2.25.1
Reviewed-by on v3 2/2
#4 lore raw

Re: [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures

Quoted 28 lines · Chenguang Zhao

From: Chenguang Zhao <[email protected]>

sxgbe_open() ignores the return value of init_dma_desc_rings() and continues to program DMA with invalid ring addresses when allocation fails. Check the return value and disconnect the PHY on failure.

Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
---
  drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +3 -1
index 9b48a587d5c2..70cf3619555f 100644
@@ -1078,7 +1078,9 @@ static int sxgbe_open(struct net_device *dev)
  	priv->dma_buf_sz = SXGBE_ALIGN(DMA_BUFFER_SIZE);
  	priv->tx_tc = TC_DEFAULT;
  	priv->rx_tc = TC_DEFAULT;
-	init_dma_desc_rings(dev);
+	ret = init_dma_desc_rings(dev);
+	if (ret)
+		goto init_phy_error;
 
  	/* DMA initialization and SW reset */
  	ret = sxgbe_init_dma_engine(priv);

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int sxgbe_open(struct net_device *dev) · line 1192

Quoted 4 lines
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +1 -0
@@ -1187,6 +1189,7 @@ static int sxgbe_open(struct net_device *dev)
 
  init_error:
  	free_dma_desc_resources(priv);
+init_phy_error:

nit: better to name it init_dma_error

drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c static int sxgbe_open(struct net_device *dev) · line 1195

Quoted 3 lines
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +0 -0
  	if (dev->phydev)
  		phy_disconnect(dev->phydev);
  phy_error:
maintainer
#5 lore raw
In reply to Chenguang Zhao
Quoted 4 lines · On Thu, 23 Jul 2026 10:18:18 +0800 Chenguang Zhao wrote:

init_dma_desc_rings() leaks already-allocated TX rings when RX allocation fails, and sxgbe_open() ignores its return value and continues with invalid DMA rings. Fix the cleanup path and check the error.

Byungho An, please review.

#6 lore raw
In reply to Chenguang Zhao
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:

Hello:

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

Quoted 8 lines · On Thu, 23 Jul 2026 10:18:18 +0800 you wrote:

From: Chenguang Zhao <[email protected]>

init_dma_desc_rings() leaks already-allocated TX rings when RX allocation fails, and sxgbe_open() ignores its return value and continues with invalid DMA rings. Fix the cleanup path and check the error.

[...]

Here is the summary with links:
- [net,v3,1/2] net: sxgbe: free TX rings on RX allocation failure

    https://git.kernel.org/netdev/net/c/c870f7e2890b
  - [net,v3,2/2] net: sxgbe: check descriptor ring allocation failures
    https://git.kernel.org/netdev/net/c/51b093a7ba27

You are awesome, thank you!

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