[PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()

Jianglei Nie posted 1 patch 3 years, 6 months ago
drivers/net/ethernet/aquantia/atlantic/aq_main.c | 3 ---
1 file changed, 3 deletions(-)
[PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
Posted by Jianglei Nie 3 years, 6 months ago
If aq_nic_stop() fails, aq_ndev_close() returns err without calling
aq_nic_deinit() to release the relevant memory and resource, which
will lead to a memory leak.

We can fix it by deleting the if condition judgment and goto statement to
call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.

Signed-off-by: Jianglei Nie <niejianglei2021@163.com>
---
 drivers/net/ethernet/aquantia/atlantic/aq_main.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_main.c b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
index 88595863d8bc..8a0af371e7dc 100644
--- a/drivers/net/ethernet/aquantia/atlantic/aq_main.c
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_main.c
@@ -94,11 +94,8 @@ static int aq_ndev_close(struct net_device *ndev)
 	int err = 0;
 
 	err = aq_nic_stop(aq_nic);
-	if (err < 0)
-		goto err_exit;
 	aq_nic_deinit(aq_nic, true);
 
-err_exit:
 	return err;
 }
 
-- 
2.25.1
Re: [PATCH] net: atlantic: fix potential memory leak in aq_ndev_close()
Posted by patchwork-bot+netdevbpf@kernel.org 3 years, 6 months ago
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Wed, 14 Sep 2022 09:42:38 +0800 you wrote:
> If aq_nic_stop() fails, aq_ndev_close() returns err without calling
> aq_nic_deinit() to release the relevant memory and resource, which
> will lead to a memory leak.
> 
> We can fix it by deleting the if condition judgment and goto statement to
> call aq_nic_deinit() directly after aq_nic_stop() to fix the memory leak.
> 
> [...]

Here is the summary with links:
  - net: atlantic: fix potential memory leak in aq_ndev_close()
    https://git.kernel.org/netdev/net/c/65e5d27df612

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html