Skip to contentSkip to conversation

net: sxgbe: fix descriptor ring allocation failure handling

PATCH Superseded Chenguang Zhao 2 participants 4 messages Jul 22

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

From: Chenguang Zhao <[email protected]>

Per Andrew's suggestion, split the patch into two

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 | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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

Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 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.

Mirror the TX allocation error path and release all TX rings before returning the error.

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

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

Quoted 20 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.

Mirror the TX allocation error path and release all TX rings before returning the error.

Fixes 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
---
  drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +0 -0
index 5051ada43d2f..fc7b72627f2a 100644

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

Quoted 9 lines
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +3 -0
@@ -605,6 +605,9 @@ static int init_dma_desc_rings(struct net_device *netd)
  rxalloc_err:
  	while (queue_num--)
  		free_rx_ring(priv->device, priv->rxq[queue_num], rx_rsize);
+	queue_num = SXGBE_TX_QUEUES;
+	while (queue_num--)
+		free_tx_ring(priv->device, priv->txq[queue_num], tx_rsize);
  	return ret;
  }
 

There is already some error code to clear tx rings. It makes more sense to rearrange labels to reuse already existing code.

#3 lore raw

PATCH v2 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 fc7b72627f2a..8d9f27065346 100644
@@ -1082,7 +1082,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);
@@ -1191,6 +1193,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