All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling
@ 2026-07-23  2:18 Chenguang Zhao
  2026-07-23  2:18 ` [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chenguang Zhao @ 2026-07-23  2:18 UTC (permalink / raw)
  To: bh74.an, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, chenguang.zhao, Chenguang Zhao

From: Chenguang Zhao <zhaochenguang@kylinos.cn>

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/20260722014055.157269-1-chenguang.zhao@linux.dev/

v1:
 https://lore.kernel.org/all/20260720024747.504493-1-chenguang.zhao@linux.dev/
-- 
2.25.1

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

* [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure
  2026-07-23  2:18 [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
@ 2026-07-23  2:18 ` Chenguang Zhao
  2026-07-23 10:07   ` Vadim Fedorenko
  2026-07-23  2:18 ` [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
  2026-07-23 13:42 ` [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Jakub Kicinski
  2 siblings, 1 reply; 6+ messages in thread
From: Chenguang Zhao @ 2026-07-23  2:18 UTC (permalink / raw)
  To: bh74.an, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, chenguang.zhao, Chenguang Zhao

From: Chenguang Zhao <zhaochenguang@kylinos.cn>

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")
Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
---
 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index 5051ada43d2f..9b48a587d5c2 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -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;
 }
 
-- 
2.25.1


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

* [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures
  2026-07-23  2:18 [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
  2026-07-23  2:18 ` [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
@ 2026-07-23  2:18 ` Chenguang Zhao
  2026-07-23 10:11   ` Vadim Fedorenko
  2026-07-23 13:42 ` [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Jakub Kicinski
  2 siblings, 1 reply; 6+ messages in thread
From: Chenguang Zhao @ 2026-07-23  2:18 UTC (permalink / raw)
  To: bh74.an, andrew+netdev, davem, edumazet, kuba, pabeni
  Cc: netdev, chenguang.zhao, Chenguang Zhao

From: Chenguang Zhao <zhaochenguang@kylinos.cn>

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")
Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
---
 drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index 9b48a587d5c2..70cf3619555f 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -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:
-- 
2.25.1


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

* Re: [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure
  2026-07-23  2:18 ` [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
@ 2026-07-23 10:07   ` Vadim Fedorenko
  0 siblings, 0 replies; 6+ messages in thread
From: Vadim Fedorenko @ 2026-07-23 10:07 UTC (permalink / raw)
  To: Chenguang Zhao, bh74.an, andrew+netdev, davem, edumazet, kuba,
	pabeni
  Cc: netdev, Chenguang Zhao

On 23/07/2026 03:18, Chenguang Zhao wrote:
> From: Chenguang Zhao <zhaochenguang@kylinos.cn>
> 
> 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")
> Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
> ---
>   drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> index 5051ada43d2f..9b48a587d5c2 100644
> --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> @@ -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;
>   }
>   
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures
  2026-07-23  2:18 ` [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
@ 2026-07-23 10:11   ` Vadim Fedorenko
  0 siblings, 0 replies; 6+ messages in thread
From: Vadim Fedorenko @ 2026-07-23 10:11 UTC (permalink / raw)
  To: Chenguang Zhao, bh74.an, andrew+netdev, davem, edumazet, kuba,
	pabeni
  Cc: netdev, Chenguang Zhao

On 23/07/2026 03:18, Chenguang Zhao wrote:
> From: Chenguang Zhao <zhaochenguang@kylinos.cn>
> 
> 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")
> Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
> ---
>   drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> index 9b48a587d5c2..70cf3619555f 100644
> --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> @@ -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:

nit: better to name it init_dma_error

>   	if (dev->phydev)
>   		phy_disconnect(dev->phydev);
>   phy_error:

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling
  2026-07-23  2:18 [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
  2026-07-23  2:18 ` [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
  2026-07-23  2:18 ` [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
@ 2026-07-23 13:42 ` Jakub Kicinski
  2 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2026-07-23 13:42 UTC (permalink / raw)
  To: bh74.an
  Cc: Chenguang Zhao, andrew+netdev, davem, edumazet, pabeni, netdev,
	Chenguang Zhao

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.

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

end of thread, other threads:[~2026-07-23 13:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-23  2:18 [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
2026-07-23  2:18 ` [PATCH net v3 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
2026-07-23 10:07   ` Vadim Fedorenko
2026-07-23  2:18 ` [PATCH net v3 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
2026-07-23 10:11   ` Vadim Fedorenko
2026-07-23 13:42 ` [PATCH net v3 0/2] net: sxgbe: fix descriptor ring allocation failure handling Jakub Kicinski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.