diff mbox series

[net] net: xilinx: axienet: fix potential memory leak in axienet_start_xmit()

Message ID 20241014143704.31938-1-wanghai38@huawei.com (mailing list archive)
State New, archived
Headers show
Series [net] net: xilinx: axienet: fix potential memory leak in axienet_start_xmit() | expand

Commit Message

Wang Hai Oct. 14, 2024, 2:37 p.m. UTC
The axienet_start_xmit() returns NETDEV_TX_OK without freeing skb
in case of dma_map_single() fails, add dev_kfree_skb_any() to fix it.

Fixes: 71791dc8bdea ("net: axienet: Check for DMA mapping errors")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Radhey Shyam Pandey Oct. 14, 2024, 5:12 p.m. UTC | #1
> -----Original Message-----
> From: Wang Hai <wanghai38@huawei.com>
> Sent: Monday, October 14, 2024 8:07 PM
> To: Pandey, Radhey Shyam <radhey.shyam.pandey@amd.com>;
> davem@davemloft.net; edumazet@google.com; kuba@kernel.org;
> pabeni@redhat.com; Simek, Michal <michal.simek@amd.com>;
> andre.przywara@arm.com; zhangxiaoxu5@huawei.com
> Cc: netdev@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-
> kernel@vger.kernel.org; wanghai38@huawei.com
> Subject: [PATCH net] net: xilinx: axienet: fix potential memory leak in
> axienet_start_xmit()
> 
> The axienet_start_xmit() returns NETDEV_TX_OK without freeing skb in case of
> dma_map_single() fails, add dev_kfree_skb_any() to fix it.
> 
> Fixes: 71791dc8bdea ("net: axienet: Check for DMA mapping errors")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>

Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Thanks!
> ---
>  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index ea7d7c03f48e..53cf1a927278 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> @@ -1046,6 +1046,7 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device
> *ndev)
>  		if (net_ratelimit())
>  			netdev_err(ndev, "TX DMA mapping error\n");
>  		ndev->stats.tx_dropped++;
> +		dev_kfree_skb_any(skb);
>  		return NETDEV_TX_OK;
>  	}
>  	desc_set_phys_addr(lp, phys, cur_p);
> @@ -1066,6 +1067,7 @@ axienet_start_xmit(struct sk_buff *skb, struct net_device
> *ndev)
>  			ndev->stats.tx_dropped++;
>  			axienet_free_tx_chain(lp, orig_tail_ptr, ii + 1,
>  					      true, NULL, 0);
> +			dev_kfree_skb_any(skb);
>  			return NETDEV_TX_OK;
>  		}
>  		desc_set_phys_addr(lp, phys, cur_p);
> --
> 2.17.1
patchwork-bot+netdevbpf@kernel.org Oct. 15, 2024, 6:10 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 14 Oct 2024 22:37:04 +0800 you wrote:
> The axienet_start_xmit() returns NETDEV_TX_OK without freeing skb
> in case of dma_map_single() fails, add dev_kfree_skb_any() to fix it.
> 
> Fixes: 71791dc8bdea ("net: axienet: Check for DMA mapping errors")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>
> ---
>  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++
>  1 file changed, 2 insertions(+)

Here is the summary with links:
  - [net] net: xilinx: axienet: fix potential memory leak in axienet_start_xmit()
    https://git.kernel.org/netdev/net/c/99714e37e833

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index ea7d7c03f48e..53cf1a927278 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -1046,6 +1046,7 @@  axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 		if (net_ratelimit())
 			netdev_err(ndev, "TX DMA mapping error\n");
 		ndev->stats.tx_dropped++;
+		dev_kfree_skb_any(skb);
 		return NETDEV_TX_OK;
 	}
 	desc_set_phys_addr(lp, phys, cur_p);
@@ -1066,6 +1067,7 @@  axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 			ndev->stats.tx_dropped++;
 			axienet_free_tx_chain(lp, orig_tail_ptr, ii + 1,
 					      true, NULL, 0);
+			dev_kfree_skb_any(skb);
 			return NETDEV_TX_OK;
 		}
 		desc_set_phys_addr(lp, phys, cur_p);