linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
@ 2023-06-14  9:17 Christian Marangi
  2023-06-14 19:17 ` Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christian Marangi @ 2023-06-14  9:17 UTC (permalink / raw)
  To: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
	Russell King, Christian Marangi, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel
  Cc: Jose Abreu, stable

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.

Reported-by: Jose Abreu <Jose.Abreu@synopsys.com>
Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Cc: stable@vger.kernel.org
---

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(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index fa07b0d50b46..5c645b6d5660 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -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);
 	}
 
-- 
2.40.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
  2023-06-14  9:17 [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Christian Marangi
@ 2023-06-14 19:17 ` Simon Horman
  2023-06-15  6:18 ` Jose Abreu
  2023-06-15 22:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-06-14 19:17 UTC (permalink / raw)
  To: Christian Marangi
  Cc: Giuseppe Cavallaro, Alexandre Torgue, Jose Abreu, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Maxime Coquelin,
	Russell King, netdev, linux-stm32, linux-arm-kernel, linux-kernel,
	Jose Abreu, stable

On Wed, Jun 14, 2023 at 11:17:14AM +0200, Christian Marangi wrote:
> 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.
> 
> Reported-by: Jose Abreu <Jose.Abreu@synopsys.com>
> Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> Cc: stable@vger.kernel.org

Reviewed-by: Simon Horman <simon.horman@corigine.com>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* RE: [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
  2023-06-14  9:17 [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Christian Marangi
  2023-06-14 19:17 ` Simon Horman
@ 2023-06-15  6:18 ` Jose Abreu
  2023-06-15 22:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Jose Abreu @ 2023-06-15  6:18 UTC (permalink / raw)
  To: Christian Marangi, Giuseppe Cavallaro, Alexandre Torgue,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Maxime Coquelin, Russell King, netdev@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
  Cc: stable@vger.kernel.org, Jose Abreu

From: Christian Marangi <ansuelsmth@gmail.com>
Date: Wed, Jun 14, 2023 at 10:17:14

> 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.
> 
> Reported-by: Jose Abreu <Jose.Abreu@synopsys.com>
> Fixes: ba39b344e924 ("net: ethernet: stmicro: stmmac: generate stmmac dma conf before open")
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> Cc: stable@vger.kernel.org

Thanks for the fix.

Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com>

Thanks,
Jose

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open
  2023-06-14  9:17 [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Christian Marangi
  2023-06-14 19:17 ` Simon Horman
  2023-06-15  6:18 ` Jose Abreu
@ 2023-06-15 22:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-15 22:10 UTC (permalink / raw)
  To: Christian Marangi
  Cc: peppe.cavallaro, alexandre.torgue, joabreu, davem, edumazet, kuba,
	pabeni, mcoquelin.stm32, linux, netdev, linux-stm32,
	linux-arm-kernel, linux-kernel, Jose.Abreu, stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 14 Jun 2023 11:17:14 +0200 you wrote:
> 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.
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-06-15 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14  9:17 [net PATCH v2] net: ethernet: stmicro: stmmac: fix possible memory leak in __stmmac_open Christian Marangi
2023-06-14 19:17 ` Simon Horman
2023-06-15  6:18 ` Jose Abreu
2023-06-15 22:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).