* [PATCH net v2 0/2] net: sxgbe: fix descriptor ring allocation failure handling
@ 2026-07-22 1:40 Chenguang Zhao
2026-07-22 1:40 ` [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
2026-07-22 1:40 ` [PATCH net v2 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
0 siblings, 2 replies; 4+ messages in thread
From: Chenguang Zhao @ 2026-07-22 1:40 UTC (permalink / raw)
To: bh74.an, andrew+netdev, davem, edumazet, kuba, pabeni
Cc: netdev, chenguang.zhao, Chenguang Zhao
From: Chenguang Zhao <zhaochenguang@kylinos.cn>
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/20260720024747.504493-1-chenguang.zhao@linux.dev/
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure
2026-07-22 1:40 [PATCH net v2 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
@ 2026-07-22 1:40 ` Chenguang Zhao
2026-07-22 10:50 ` Vadim Fedorenko
2026-07-22 1:40 ` [PATCH net v2 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
1 sibling, 1 reply; 4+ messages in thread
From: Chenguang Zhao @ 2026-07-22 1:40 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.
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")
Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
---
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index 5051ada43d2f..fc7b72627f2a 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v2 2/2] net: sxgbe: check descriptor ring allocation failures
2026-07-22 1:40 [PATCH net v2 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
2026-07-22 1:40 ` [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
@ 2026-07-22 1:40 ` Chenguang Zhao
1 sibling, 0 replies; 4+ messages in thread
From: Chenguang Zhao @ 2026-07-22 1:40 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 fc7b72627f2a..8d9f27065346 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -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:
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure
2026-07-22 1:40 ` [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
@ 2026-07-22 10:50 ` Vadim Fedorenko
0 siblings, 0 replies; 4+ messages in thread
From: Vadim Fedorenko @ 2026-07-22 10:50 UTC (permalink / raw)
To: Chenguang Zhao, bh74.an, andrew+netdev, davem, edumazet, kuba,
pabeni
Cc: netdev, Chenguang Zhao
On 22/07/2026 02:40, 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.
>
> 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")
> Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
> ---
> drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> index 5051ada43d2f..fc7b72627f2a 100644
> --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
> @@ -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.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-22 10:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 1:40 [PATCH net v2 0/2] net: sxgbe: fix descriptor ring allocation failure handling Chenguang Zhao
2026-07-22 1:40 ` [PATCH net v2 1/2] net: sxgbe: free TX rings on RX allocation failure Chenguang Zhao
2026-07-22 10:50 ` Vadim Fedorenko
2026-07-22 1:40 ` [PATCH net v2 2/2] net: sxgbe: check descriptor ring allocation failures Chenguang Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox