* [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
@ 2022-11-20 3:54 Ziyang Xuan
2022-11-20 11:49 ` Lorenzo Bianconi
2022-11-23 5:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Ziyang Xuan @ 2022-11-20 3:54 UTC (permalink / raw)
To: nbd, john, sean.wang, Mark-MC.Lee, davem, edumazet, kuba, pabeni,
matthias.bgg, linux, netdev, linux-arm-kernel, linux-mediatek
Cc: linux-kernel, lorenzo
When fail to dma_map_single() in mtk_rx_alloc(), it returns directly.
But the memory allocated for local variable data is not freed, and
local variabel data has not been attached to ring->data[i] yet, so the
memory allocated for local variable data will not be freed outside
mtk_rx_alloc() too. Thus memory leak would occur in this scenario.
Add skb_free_frag(data) when dma_map_single() failed.
Fixes: 23233e577ef9 ("net: ethernet: mtk_eth_soc: rely on page_pool for single page buffers")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 7cd381530aa4..bc47ef1e4dd5 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -2378,8 +2378,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
data + NET_SKB_PAD + eth->ip_align,
ring->buf_size, DMA_FROM_DEVICE);
if (unlikely(dma_mapping_error(eth->dma_dev,
- dma_addr)))
+ dma_addr))) {
+ skb_free_frag(data);
return -ENOMEM;
+ }
}
rxd->rxd1 = (unsigned int)dma_addr;
ring->data[i] = data;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
2022-11-20 3:54 [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc() Ziyang Xuan
@ 2022-11-20 11:49 ` Lorenzo Bianconi
2022-11-23 5:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Bianconi @ 2022-11-20 11:49 UTC (permalink / raw)
To: Ziyang Xuan
Cc: nbd, john, sean.wang, Mark-MC.Lee, davem, edumazet, kuba, pabeni,
matthias.bgg, linux, netdev, linux-arm-kernel, linux-mediatek,
linux-kernel, lorenzo
[-- Attachment #1: Type: text/plain, Size: 1473 bytes --]
> When fail to dma_map_single() in mtk_rx_alloc(), it returns directly.
> But the memory allocated for local variable data is not freed, and
> local variabel data has not been attached to ring->data[i] yet, so the
> memory allocated for local variable data will not be freed outside
> mtk_rx_alloc() too. Thus memory leak would occur in this scenario.
>
> Add skb_free_frag(data) when dma_map_single() failed.
>
> Fixes: 23233e577ef9 ("net: ethernet: mtk_eth_soc: rely on page_pool for single page buffers")
> Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
> ---
> drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 7cd381530aa4..bc47ef1e4dd5 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -2378,8 +2378,10 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag)
> data + NET_SKB_PAD + eth->ip_align,
> ring->buf_size, DMA_FROM_DEVICE);
> if (unlikely(dma_mapping_error(eth->dma_dev,
> - dma_addr)))
> + dma_addr))) {
> + skb_free_frag(data);
> return -ENOMEM;
> + }
> }
> rxd->rxd1 = (unsigned int)dma_addr;
> ring->data[i] = data;
> --
> 2.25.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
2022-11-20 3:54 [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc() Ziyang Xuan
2022-11-20 11:49 ` Lorenzo Bianconi
@ 2022-11-23 5:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-23 5:00 UTC (permalink / raw)
To: Ziyang Xuan
Cc: nbd, john, sean.wang, Mark-MC.Lee, davem, edumazet, kuba, pabeni,
matthias.bgg, linux, netdev, linux-arm-kernel, linux-mediatek,
linux-kernel, lorenzo
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 20 Nov 2022 11:54:05 +0800 you wrote:
> When fail to dma_map_single() in mtk_rx_alloc(), it returns directly.
> But the memory allocated for local variable data is not freed, and
> local variabel data has not been attached to ring->data[i] yet, so the
> memory allocated for local variable data will not be freed outside
> mtk_rx_alloc() too. Thus memory leak would occur in this scenario.
>
> Add skb_free_frag(data) when dma_map_single() failed.
>
> [...]
Here is the summary with links:
- [net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
https://git.kernel.org/netdev/net/c/3213f808ae21
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-23 5:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20 3:54 [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc() Ziyang Xuan
2022-11-20 11:49 ` Lorenzo Bianconi
2022-11-23 5:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).