[PATCH] net: mana: Fix memory leak in mana_hwc_create_wq

Subsystems: hyper-v/azure core and drivers, networking drivers, the rest

STALE1774d LANDED

Landed in mainline as 9acfc57fa2b8 on 2021-12-09.

3 messages, 3 authors, 2021-12-09 · open the first message on its own page

[PATCH] net: mana: Fix memory leak in mana_hwc_create_wq

From: José Expósito <hidden>
Date: 2021-12-08 22:37:48

If allocating the DMA buffer fails, mana_hwc_destroy_wq was called
without previously storing the pointer to the queue.

In order to avoid leaking the pointer to the queue, store it as soon as
it is allocated.

Addresses-Coverity-ID: 1484720 ("Resource leak")
Signed-off-by: José Expósito <redacted>
---
 drivers/net/ethernet/microsoft/mana/hw_channel.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c
index 34b971ff8ef8..078d6a5a0768 100644
--- a/drivers/net/ethernet/microsoft/mana/hw_channel.c
+++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c
@@ -480,16 +480,16 @@ static int mana_hwc_create_wq(struct hw_channel_context *hwc,
 	if (err)
 		goto out;
 
-	err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size,
-				     &hwc_wq->msg_buf);
-	if (err)
-		goto out;
-
 	hwc_wq->hwc = hwc;
 	hwc_wq->gdma_wq = queue;
 	hwc_wq->queue_depth = q_depth;
 	hwc_wq->hwc_cq = hwc_cq;
 
+	err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size,
+				     &hwc_wq->msg_buf);
+	if (err)
+		goto out;
+
 	*hwc_wq_ptr = hwc_wq;
 	return 0;
 out:
-- 
2.25.1

RE: [PATCH] net: mana: Fix memory leak in mana_hwc_create_wq

From: Dexuan Cui <decui@microsoft.com>
Date: 2021-12-09 00:32:50

From: José Expósito <redacted>
Sent: Wednesday, December 8, 2021 2:37 PM

If allocating the DMA buffer fails, mana_hwc_destroy_wq was called
without previously storing the pointer to the queue.

In order to avoid leaking the pointer to the queue, store it as soon as
it is allocated.

Addresses-Coverity-ID: 1484720 ("Resource leak")
Signed-off-by: José Expósito <redacted>
Reviewed-by: Dexuan Cui <decui@microsoft.com>

Re: [PATCH] net: mana: Fix memory leak in mana_hwc_create_wq

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-12-09 16:10:16

Hello:

This patch was applied to netdev/net.git (master)
by Jakub Kicinski [off-list ref]:

On Wed,  8 Dec 2021 23:37:23 +0100 you wrote:
If allocating the DMA buffer fails, mana_hwc_destroy_wq was called
without previously storing the pointer to the queue.

In order to avoid leaking the pointer to the queue, store it as soon as
it is allocated.

Addresses-Coverity-ID: 1484720 ("Resource leak")
Signed-off-by: José Expósito <redacted>

[...]
Here is the summary with links:
  - net: mana: Fix memory leak in mana_hwc_create_wq
    https://git.kernel.org/netdev/net/c/9acfc57fa2b8

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

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help