eth: fbnic: avoid double free when failing to DMA-map FW msg
Subsystems (3)
Jakub Kicinski
maintainerPATCH 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.
--- 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
@@ -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
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 msgThe 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")Reviewed-by Alexander Duyck <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>--- 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
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
-1mbx->buf_info[tail].msg = msg; mbx->buf_info[tail].addr = addr; --2.49.0
Paolo Abeni
maintainerQuoted 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
Jakub Kicinski
maintainerQuoted 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.
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")Reviewed-by Alexander Duyck <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>[...]
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