net/bnxt: fix memory leak when freeing VF info
authorYunjian Wang <wangyunjian@huawei.com>
Fri, 31 Jul 2020 12:08:55 +0000 (20:08 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 18 Sep 2020 16:55:07 +0000 (18:55 +0200)
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>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt_ethdev.c
drivers/net/bnxt/bnxt_hwrm.c
drivers/net/bnxt/bnxt_hwrm.h

index 510a0d9..e64c147 100644 (file)
@@ -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;
index 8296d1d..643dd98 100644 (file)
@@ -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;
index 4a2af13..eaabe1f 100644 (file)
@@ -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