net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
Subsystems (5)
PATCH v2 1/1 net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
Fix a possible memory leak in __stmmac_open when stmmac_init_phy fails. It's also needed to free everything allocated by stmmac_setup_dma_desc and not just the dma_conf struct.
Drop free_dma_desc_resources from __stmmac_open and correctly call free_dma_desc_resources on each user of __stmmac_open on error.
---
Changes v2:
- Move free_dma_desc_resources to each user of __stmmac_open
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +7 -2
@@ -3877,7 +3877,6 @@ static int __stmmac_open(struct net_device *dev,stmmac_hw_teardown (dev); init_error: -free_dma_desc_resources (priv, &priv->dma_conf);phylink_disconnect_phy (priv->phylink); init_phy_error:pm_runtime_put (priv->device);
@@ -3895,6 +3894,9 @@ static int stmmac_open(struct net_device *dev)return PTR_ERR (dma_conf); ret =__stmmac_open (dev, dma_conf); +if (ret) +free_dma_desc_resources (priv, dma_conf); +kfree (dma_conf);return ret; }
@@ -5637,12 +5639,15 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)stmmac_release (dev); ret =__stmmac_open (dev, dma_conf); -kfree (dma_conf);if (ret) { +free_dma_desc_resources (priv, dma_conf); +kfree (dma_conf);netdev_err (priv->dev,"failed reopening the interface after MTU change\n" );return ret; } +kfree (dma_conf); +stmmac_set_rx_mode (dev); }
Signature · 1 line
2.40.1
Quoted 11 lines · Christian Marangi
Fix a possible memory leak in
__stmmac_openwhenstmmac_init_phyfails. It's also needed to free everything allocated bystmmac_setup_dma_descand not just thedma_confstruct.Drop
free_dma_desc_resourcesfrom__stmmac_openand correctly callfree_dma_desc_resourceson each user of__stmmac_openon error.Reported-by Jose Abreu <[email protected]>Fixes ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")Signed-off-by Christian Marangi <[email protected]>
From: Christian Marangi <[email protected]>
Date: Wed, Jun 14, 2023 at 10:17:14
Quoted 11 lines
Fix a possible memory leak in
__stmmac_openwhenstmmac_init_phyfails. It's also needed to free everything allocated bystmmac_setup_dma_descand not just thedma_confstruct.Drop
free_dma_desc_resourcesfrom__stmmac_openand correctly callfree_dma_desc_resourceson each user of__stmmac_openon error.Reported-by Jose Abreu <[email protected]>Fixes ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")Signed-off-by Christian Marangi <[email protected]>
Thanks for the fix.
Thanks,
Jose
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 14 Jun 2023 11:17:14 +0200 you wrote:
Fix a possible memory leak in
__stmmac_openwhenstmmac_init_phyfails. It's also needed to free everything allocated bystmmac_setup_dma_descand not just thedma_confstruct.Drop
free_dma_desc_resourcesfrom__stmmac_openand correctly callfree_dma_desc_resourceson each user of__stmmac_openon error.[...]
Here is the summary with links:
- [net,v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
https://git.kernel.org/netdev/net/c/30134b7c47bd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html