Skip to contentSkip to conversation

eth: fbnic: avoid double free when failing to DMA-map FW msg

PATCH Applied Jakub Kicinski 4 participants 5 messages Jun 16, 2025 – Jun 19, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 eth: fbnic: avoid double free when failing to DMA-map FW msg

The semantics are that caller of fbnic_mbx_map_msg() retains the ownership of the message on error. All existing callers dutifully free the page.

Fixes da3cde08209e ("eth: fbnic: Add FW communication mechanism")
---
 drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +1 -4
index edd4adad954a..72c688b17c5b 100644
@@ -127,11 +127,8 @@ static int fbnic_mbx_map_msg(struct fbnic_dev *fbd, int mbx_idx,
 		return -EBUSY;
 
 	addr = dma_map_single(fbd->dev, msg, PAGE_SIZE, direction);
-	if (dma_mapping_error(fbd->dev, addr)) {
-		free_page((unsigned long)msg);
-
+	if (dma_mapping_error(fbd->dev, addr))
 		return -ENOSPC;
-	}
 
 	mbx->buf_info[tail].msg = msg;
 	mbx->buf_info[tail].addr = addr;
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 30 lines

-----Original Message-----
From: Jakub Kicinski <[email protected]>
Sent: Monday, June 16, 2025 12:55 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Keller, Jacob E <[email protected]>; Jakub Kicinski <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] eth: fbnic: avoid double free when failing to DMA-map FW msg

The semantics are that caller of fbnic_mbx_map_msg() retains the ownership of the message on error. All existing callers dutifully free the page.

Fixes da3cde08209e ("eth: fbnic: Add FW communication mechanism")
---
 drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +0 -0
index edd4adad954a..72c688b17c5b 100644

drivers/net/ethernet/meta/fbnic/fbnic_fw.c static int fbnic_mbx_map_msg(struct fbnic_dev *fbd, int · line 135

Quoted 10 lines
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +1 -4
@@ -127,11 +127,8 @@ static int fbnic_mbx_map_msg(struct fbnic_dev *fbd, int
 mbx_idx,
 		return -EBUSY;
 
 	addr = dma_map_single(fbd->dev, msg, PAGE_SIZE, direction);
-	if (dma_mapping_error(fbd->dev, addr)) {
-		free_page((unsigned long)msg);
-
+	if (dma_mapping_error(fbd->dev, addr))
 		return -ENOSPC;
-	}

Makes sense. It doesn't look like you free_page on other errors either.

Quoted 5 lines
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +0 -1
 	mbx->buf_info[tail].msg = msg;
 	mbx->buf_info[tail].addr = addr;
--

2.49.0

maintainer
#2 lore raw
In reply to Jakub Kicinski
Quoted 2 lines · Jakub Kicinski

The semantics are that caller of fbnic_mbx_map_msg() retains the ownership of the message on error.

FWIW, I think the opposite semantic would lead to simpler/smaller code overall, but no objections to retain the current one.

/P

author maintainer
#3 lore raw
Quoted 6 lines · On Thu, 19 Jun 2025 12:18:58 +0200 Paolo Abeni wrote:
Quoted 2 lines · Jakub Kicinski

The semantics are that caller of fbnic_mbx_map_msg() retains the ownership of the message on error.

FWIW, I think the opposite semantic would lead to simpler/smaller code overall, but no objections to retain the current one.

Interesting, I'd have thought the semantics of "on error caller retains the ownership of the object they are trying to hand over" are generally considered more intuitive.

#4 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 16 Jun 2025 12:55:10 -0700 you wrote:

The semantics are that caller of fbnic_mbx_map_msg() retains the ownership of the message on error. All existing callers dutifully free the page.

Fixes da3cde08209e ("eth: fbnic: Add FW communication mechanism")

[...]

Here is the summary with links:
- [net] eth: fbnic: avoid double free when failing to DMA-map FW msg

    https://git.kernel.org/netdev/net/c/5bd1bafd4474

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html