diff mbox series

[4/9] net/bnxt: fix error handling when VNIC prepare fails

Message ID 20210531072644.24656-5-kalesh-anakkur.purayil@broadcom.com (mailing list archive)
State Accepted
Delegated to: Ajit Khaparde
Headers show
Series bnxt PMD fixes | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Kalesh A P May 31, 2021, 7:26 a.m. UTC
From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

Resources should be freed on error conditions. i.e, VNIC and
VNIC context created in HW and memory allocated in
bnxt_vnic_grp_alloc() should be freed.

Added a new function bnxt_vnic_destroy() to do the cleanup.
This lightweight function can be used in flow destroy/flush
path to avoid duplicate code as well.

Fixes: d24610f7bfda ("net/bnxt: allow flow creation when RSS is enabled")
Cc: stable@dpdk.org

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
---
 drivers/net/bnxt/bnxt_flow.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/bnxt/bnxt_flow.c b/drivers/net/bnxt/bnxt_flow.c
index d23f8cf..03c7173 100644
--- a/drivers/net/bnxt/bnxt_flow.c
+++ b/drivers/net/bnxt/bnxt_flow.c
@@ -919,6 +919,19 @@  bnxt_get_l2_filter(struct bnxt *bp, struct bnxt_filter_info *nf,
 	return l2_filter;
 }
 
+static void bnxt_vnic_cleanup(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+{
+	if (vnic->rx_queue_cnt > 1)
+		bnxt_hwrm_vnic_ctx_free(bp, vnic);
+
+	bnxt_hwrm_vnic_free(bp, vnic);
+
+	rte_free(vnic->fw_grp_ids);
+	vnic->fw_grp_ids = NULL;
+
+	vnic->rx_queue_cnt = 0;
+}
+
 static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic,
 			  const struct rte_flow_action *act,
 			  struct rte_flow_error *error)
@@ -949,8 +962,6 @@  static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic,
 		goto ret;
 	}
 
-	bp->nr_vnics++;
-
 	/* RSS context is required only when there is more than one RSS ring */
 	if (vnic->rx_queue_cnt > 1) {
 		rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic, 0);
@@ -986,9 +997,12 @@  static int bnxt_vnic_prep(struct bnxt *bp, struct bnxt_vnic_info *vnic,
 		goto ret;
 	}
 
+	bp->nr_vnics++;
+
 	return 0;
 
 ret:
+	bnxt_vnic_cleanup(bp, vnic);
 	return rc;
 }