patches for DPDK stable branches
 help / color / mirror / Atom feed
From: wangyunjian <wangyunjian@huawei.com>
To: <dev@dpdk.org>
Cc: <ajit.khaparde@broadcom.com>, <somnath.kotur@broadcom.com>,
	<jerry.lilijun@huawei.com>, <xudingke@huawei.com>,
	Yunjian Wang <wangyunjian@huawei.com>, <stable@dpdk.org>
Subject: [dpdk-stable] [dpdk-dev] [PATCH 1/2] net/bnxt: fix memory leak when freeing vf_info
Date: Fri, 31 Jul 2020 20:08:55 +0800	[thread overview]
Message-ID: <4e9c6206a7fd6a119349df92ce6b3e625eedb2da.1596196484.git.wangyunjian@huawei.com> (raw)
In-Reply-To: <cover.1596196484.git.wangyunjian@huawei.com>

From: Yunjian Wang <wangyunjian@huawei.com>

When freeing a vf_info, we should free the 'vlan_as_table'
and 'vlan_table' for the vf_info.

Fixes: b7778e8a1c00 ("net/bnxt: refactor to properly allocate resources for PF/VF")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/bnxt/bnxt_ethdev.c |  3 +--
 drivers/net/bnxt/bnxt_hwrm.c   | 16 +++++++++++++++-
 drivers/net/bnxt/bnxt_hwrm.h   |  1 +
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 510a0d9e0..e64c147be 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1360,8 +1360,7 @@ static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
 	rte_memzone_free((const struct rte_memzone *)bp->rx_mem_zone);
 	bp->rx_mem_zone = NULL;
 
-	rte_free(bp->pf->vf_info);
-	bp->pf->vf_info = NULL;
+	bnxt_hwrm_free_vf_info(bp);
 
 	rte_free(bp->grp_info);
 	bp->grp_info = NULL;
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index 8296d1d44..643dd9897 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -670,6 +670,20 @@ static int bnxt_hwrm_ptp_qcfg(struct bnxt *bp)
 	return 0;
 }
 
+void bnxt_hwrm_free_vf_info(struct bnxt *bp)
+{
+	int i;
+
+	for (i = 0; i < bp->pf->max_vfs; i++) {
+		rte_free(bp->pf->vf_info[i].vlan_table);
+		bp->pf->vf_info[i].vlan_table = NULL;
+		rte_free(bp->pf->vf_info[i].vlan_as_table);
+		bp->pf->vf_info[i].vlan_as_table = NULL;
+	}
+	rte_free(bp->pf->vf_info);
+	bp->pf->vf_info = NULL;
+}
+
 static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
 {
 	int rc = 0;
@@ -696,7 +710,7 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
 		new_max_vfs = bp->pdev->max_vfs;
 		if (new_max_vfs != bp->pf->max_vfs) {
 			if (bp->pf->vf_info)
-				rte_free(bp->pf->vf_info);
+				bnxt_hwrm_free_vf_info(bp);
 			bp->pf->vf_info = rte_malloc("bnxt_vf_info",
 			    sizeof(bp->pf->vf_info[0]) * new_max_vfs, 0);
 			bp->pf->max_vfs = new_max_vfs;
diff --git a/drivers/net/bnxt/bnxt_hwrm.h b/drivers/net/bnxt/bnxt_hwrm.h
index 4a2af13c9..eaabe1ffc 100644
--- a/drivers/net/bnxt/bnxt_hwrm.h
+++ b/drivers/net/bnxt/bnxt_hwrm.h
@@ -280,4 +280,5 @@ int bnxt_clear_one_vnic_filter(struct bnxt *bp,
 			       struct bnxt_filter_info *filter);
 int bnxt_hwrm_cfa_vfr_alloc(struct bnxt *bp, uint16_t vf_idx);
 int bnxt_hwrm_cfa_vfr_free(struct bnxt *bp, uint16_t vf_idx);
+void bnxt_hwrm_free_vf_info(struct bnxt *bp);
 #endif
-- 
2.23.0



       reply	other threads:[~2020-07-31 12:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1596196484.git.wangyunjian@huawei.com>
2020-07-31 12:08 ` wangyunjian [this message]
2020-07-31 12:09 ` [dpdk-stable] [dpdk-dev] [PATCH 2/2] net/bnxt: add memory allocation check in vf_info init wangyunjian

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=4e9c6206a7fd6a119349df92ce6b3e625eedb2da.1596196484.git.wangyunjian@huawei.com \
    --to=wangyunjian@huawei.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=dev@dpdk.org \
    --cc=jerry.lilijun@huawei.com \
    --cc=somnath.kotur@broadcom.com \
    --cc=stable@dpdk.org \
    --cc=xudingke@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;
as well as URLs for NNTP newsgroup(s).