From: Paolo Abeni <pabeni@redhat.com>
To: Haoxiang Li <haoxiang_li2024@163.com>,
shshaikh@marvell.com, manishc@marvell.com,
GR-Linux-NIC-Dev@marvell.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
rajesh.borundia@qlogic.com, sucheta.chakraborty@qlogic.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] qlcnic: fix a memory leak in qlcnic_sriov_set_guest_vlan_mode()
Date: Thu, 6 Mar 2025 11:32:08 +0100 [thread overview]
Message-ID: <8ec75d7c-0fcf-4f7f-9505-31ec3dae4bdd@redhat.com> (raw)
In-Reply-To: <20250305100950.4001113-1-haoxiang_li2024@163.com>
On 3/5/25 11:09 AM, Haoxiang Li wrote:
> Add qlcnic_sriov_free_vlans() to free the memory allocated by
> qlcnic_sriov_alloc_vlans() if qlcnic_sriov_alloc_vlans() fails
> or "sriov->allowed_vlans" fails to be allocated.
>
> Fixes: 91b7282b613d ("qlcnic: Support VLAN id config.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
> ---
> Changes in v2:
> - Add qlcnic_sriov_free_vlans() if qlcnic_sriov_alloc_vlans() fails.
> - Modify the patch description.
> vf_info was allocated by kcalloc, no need to do more checks cause
> kfree(NULL) is safe. Thanks, Paolo!
> ---
> drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
> index f9dd50152b1e..0dd9d7cb1de9 100644
> --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
> +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
> @@ -446,16 +446,20 @@ static int qlcnic_sriov_set_guest_vlan_mode(struct qlcnic_adapter *adapter,
> sriov->num_allowed_vlans);
>
> ret = qlcnic_sriov_alloc_vlans(adapter);
> - if (ret)
> + if (ret) {
> + qlcnic_sriov_free_vlans(adapter);
I'm sorry for the lack of clarity in my previous reply. I think it would
be better to do this cleanup inside qlcnic_sriov_alloc_vlans(), so that
on error it returns with no vlan allocated.
There is another caller of qlcnic_sriov_alloc_vlans() which AFAICS still
leak memory on error. Handling the deallocation in
qlcnic_sriov_alloc_vlans() will address even that caller.
Thanks,
Paolo
next prev parent reply other threads:[~2025-03-06 10:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-05 10:09 [PATCH v2] qlcnic: fix a memory leak in qlcnic_sriov_set_guest_vlan_mode() Haoxiang Li
2025-03-06 10:32 ` Paolo Abeni [this message]
2025-03-06 10:34 ` Paolo Abeni
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=8ec75d7c-0fcf-4f7f-9505-31ec3dae4bdd@redhat.com \
--to=pabeni@redhat.com \
--cc=GR-Linux-NIC-Dev@marvell.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=haoxiang_li2024@163.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manishc@marvell.com \
--cc=netdev@vger.kernel.org \
--cc=rajesh.borundia@qlogic.com \
--cc=shshaikh@marvell.com \
--cc=stable@vger.kernel.org \
--cc=sucheta.chakraborty@qlogic.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