From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Ziyang Xuan <william.xuanziyang@huawei.com>
Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com,
Mark-MC.Lee@mediatek.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
matthias.bgg@gmail.com, linux@armlinux.org.uk,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
lorenzo@kernel.org
Subject: Re: [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
Date: Sun, 20 Nov 2022 12:49:01 +0100 [thread overview]
Message-ID: <Y3oULSsTwbDY2Bvv@lore-desk> (raw)
In-Reply-To: <20221120035405.1464341-1-william.xuanziyang@huawei.com>
[-- 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 --]
WARNING: multiple messages have this Message-ID (diff)
From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Ziyang Xuan <william.xuanziyang@huawei.com>
Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com,
Mark-MC.Lee@mediatek.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
matthias.bgg@gmail.com, linux@armlinux.org.uk,
netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
lorenzo@kernel.org
Subject: Re: [PATCH net] net: ethernet: mtk_eth_soc: fix potential memory leak in mtk_rx_alloc()
Date: Sun, 20 Nov 2022 12:49:01 +0100 [thread overview]
Message-ID: <Y3oULSsTwbDY2Bvv@lore-desk> (raw)
In-Reply-To: <20221120035405.1464341-1-william.xuanziyang@huawei.com>
[-- Attachment #1.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 #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-11-20 11:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 3:54 ` Ziyang Xuan
2022-11-20 11:49 ` Lorenzo Bianconi [this message]
2022-11-20 11:49 ` Lorenzo Bianconi
2022-11-23 5:00 ` patchwork-bot+netdevbpf
2022-11-23 5:00 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y3oULSsTwbDY2Bvv@lore-desk \
--to=lorenzo.bianconi@redhat.com \
--cc=Mark-MC.Lee@mediatek.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=john@phrozen.org \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=lorenzo@kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=nbd@nbd.name \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sean.wang@mediatek.com \
--cc=william.xuanziyang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.