netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: mhi: Fix memory leak in mhi_net_dellink()
@ 2022-11-09 10:09 Wei Yongjun
  2022-11-11  0:25 ` Jakub Kicinski
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2022-11-09 10:09 UTC (permalink / raw)
  To: Loic Poulain, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Wei Yongjun, netdev

From: Wei Yongjun <weiyongjun1@huawei.com>

MHI driver registers network device without setting the
needs_free_netdev flag, and does NOT call free_netdev() when
unregisters network device, which causes a memory leak.

This patch calls free_netdev() to fix it since netdev_priv
is used after unregister.

Fixes: 7ffa7542eca6 ("net: mhi: Remove MBIM protocol")
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 drivers/net/mhi_net.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c
index ff302144029d..3d322ac4f6a5 100644
--- a/drivers/net/mhi_net.c
+++ b/drivers/net/mhi_net.c
@@ -343,6 +343,8 @@ static void mhi_net_dellink(struct mhi_device *mhi_dev, struct net_device *ndev)
 
 	kfree_skb(mhi_netdev->skbagg_head);
 
+	free_netdev(ndev);
+
 	dev_set_drvdata(&mhi_dev->dev, NULL);
 }
 
-- 
2.34.1


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

* Re: [PATCH net] net: mhi: Fix memory leak in mhi_net_dellink()
  2022-11-09 10:09 [PATCH net] net: mhi: Fix memory leak in mhi_net_dellink() Wei Yongjun
@ 2022-11-11  0:25 ` Jakub Kicinski
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2022-11-11  0:25 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Loic Poulain, David S. Miller, Eric Dumazet, Paolo Abeni,
	Wei Yongjun, netdev

On Wed,  9 Nov 2022 10:09:15 +0000 Wei Yongjun wrote:
> MHI driver registers network device without setting the
> needs_free_netdev flag, and does NOT call free_netdev() when
> unregisters network device, which causes a memory leak.
> 
> This patch calls free_netdev() to fix it since netdev_priv
> is used after unregister.
> 
> Fixes: 7ffa7542eca6 ("net: mhi: Remove MBIM protocol")

I don't see how the bug is introduced by this commit.

Please find the correct fixes tag or add an explanation of how the bug
got added.

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

end of thread, other threads:[~2022-11-11  0:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-09 10:09 [PATCH net] net: mhi: Fix memory leak in mhi_net_dellink() Wei Yongjun
2022-11-11  0:25 ` Jakub Kicinski

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