From: Leon Romanovsky <leon@kernel.org>
To: Zhang Changzhong <zhangchangzhong@huawei.com>
Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Jose Abreu <joabreu@synopsys.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload()
Date: Wed, 7 Dec 2022 11:12:25 +0200 [thread overview]
Message-ID: <Y5BY+ZpW20XpkVZw@unreal> (raw)
In-Reply-To: <1670401920-7574-1-git-send-email-zhangchangzhong@huawei.com>
On Wed, Dec 07, 2022 at 04:31:59PM +0800, Zhang Changzhong wrote:
> The skb allocated by stmmac_test_get_arp_skb() hasn't been released in
> some error handling case, which will lead to a memory leak. Fix this up
> by adding kfree_skb() to release skb.
>
> Compile tested only.
>
> Fixes: 5e3fb0a6e2b3 ("net: stmmac: selftests: Implement the ARP Offload test")
> Signed-off-by: Zhang Changzhong <zhangchangzhong@huawei.com>
> ---
> drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
> index 49af7e7..687f43c 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
> @@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv)
> }
>
> ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
> - if (ret)
> + if (ret) {
> + kfree_skb(skb);
> goto cleanup;
> + }
>
> ret = dev_set_promiscuity(priv->dev, 1);
> - if (ret)
> + if (ret) {
> + kfree_skb(skb);
> goto cleanup;
> + }
>
> ret = dev_direct_xmit(skb, 0);
> if (ret)
You should release skb here too. So the better patch will be to write
something like that:
cleanup:
stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
if (ret)
kfree_skb(skb);
Thanks
> --
> 2.9.5
>
next prev parent reply other threads:[~2022-12-07 9:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-07 8:31 [PATCH net] net: stmmac: selftests: fix potential memleak in stmmac_test_arpoffload() Zhang Changzhong
2022-12-07 9:12 ` Leon Romanovsky [this message]
2022-12-07 10:07 ` Zhang Changzhong
2022-12-08 8:29 ` Leon Romanovsky
2022-12-09 11: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=Y5BY+ZpW20XpkVZw@unreal \
--to=leon@kernel.org \
--cc=alexandre.torgue@foss.st.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcoquelin.stm32@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peppe.cavallaro@st.com \
--cc=zhangchangzhong@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox