diff mbox series

[net,07/13] net: stmmac: Free Rx descs on Tx allocation failure

Message ID 20230313224237.28757-8-Sergey.Semin@baikalelectronics.ru (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series net: stmmac: Fixes bundle #1 | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers warning 3 maintainers not CCed: linux-mediatek@lists.infradead.org angelogioacchino.delregno@collabora.com matthias.bgg@gmail.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Serge Semin March 13, 2023, 10:42 p.m. UTC
Indeed in accordance with the alloc_dma_desc_resources() method logic the
Rx descriptors will be left allocated if Tx descriptors allocation fails.
Fix it by calling the free_dma_rx_desc_resources() in case if the
alloc_dma_tx_desc_resources() method returns non-zero value.

While at it refactor the method a bit. Just move the Rx descriptors
allocation method invocation out of the local variables declaration block
and discard a pointless comment from there.

Fixes: 71fedb0198cb ("net: stmmac: break some functions into RX and TX scopes")
Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Piotr Raczynski March 14, 2023, 9:22 a.m. UTC | #1
On Tue, Mar 14, 2023 at 01:42:31AM +0300, Serge Semin wrote:
> Indeed in accordance with the alloc_dma_desc_resources() method logic the
> Rx descriptors will be left allocated if Tx descriptors allocation fails.
> Fix it by calling the free_dma_rx_desc_resources() in case if the
> alloc_dma_tx_desc_resources() method returns non-zero value.
> 
> While at it refactor the method a bit. Just move the Rx descriptors
> allocation method invocation out of the local variables declaration block
> and discard a pointless comment from there.
> 

LGTM, Thanks.
Reviewed-by: Piotr Raczynski <piotr.raczynski@intel.com>
> Fixes: 71fedb0198cb ("net: stmmac: break some functions into RX and TX scopes")
> Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 4d643b1bbf65..229f827d7572 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -2182,13 +2182,15 @@ static int alloc_dma_tx_desc_resources(struct stmmac_priv *priv,
>  static int alloc_dma_desc_resources(struct stmmac_priv *priv,
>  				    struct stmmac_dma_conf *dma_conf)
>  {
> -	/* RX Allocation */
> -	int ret = alloc_dma_rx_desc_resources(priv, dma_conf);
> +	int ret;
>  
> +	ret = alloc_dma_rx_desc_resources(priv, dma_conf);
>  	if (ret)
>  		return ret;
>  
>  	ret = alloc_dma_tx_desc_resources(priv, dma_conf);
> +	if (ret)
> +		free_dma_rx_desc_resources(priv, dma_conf);
>  
>  	return ret;
>  }
> -- 
> 2.39.2
> 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 4d643b1bbf65..229f827d7572 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2182,13 +2182,15 @@  static int alloc_dma_tx_desc_resources(struct stmmac_priv *priv,
 static int alloc_dma_desc_resources(struct stmmac_priv *priv,
 				    struct stmmac_dma_conf *dma_conf)
 {
-	/* RX Allocation */
-	int ret = alloc_dma_rx_desc_resources(priv, dma_conf);
+	int ret;
 
+	ret = alloc_dma_rx_desc_resources(priv, dma_conf);
 	if (ret)
 		return ret;
 
 	ret = alloc_dma_tx_desc_resources(priv, dma_conf);
+	if (ret)
+		free_dma_rx_desc_resources(priv, dma_conf);
 
 	return ret;
 }