From dc0bdeb4fa79826788124a4e230c38d1c32aff2d Mon Sep 17 00:00:00 2001 From: Ajit Khaparde Date: Tue, 10 Oct 2017 09:23:00 -0500 Subject: [PATCH] net/bnxt: fix cleanup if a filter allocation fails We are not checking if a filter allocation succeeded. And we end up accessing a null pointer after that. Also invalidate the fw_l2_filter_id to prevent unnecessary HW access and hence HWRM command failures during exit. Fixes: 5ef3b79fdfe6 ("net/bnxt: support flow filter ops") Cc: stable@dpdk.org Signed-off-by: Ajit Khaparde --- drivers/net/bnxt/bnxt_filter.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/bnxt/bnxt_filter.c b/drivers/net/bnxt/bnxt_filter.c index 9f171fd995..4c1db559d3 100644 --- a/drivers/net/bnxt/bnxt_filter.c +++ b/drivers/net/bnxt/bnxt_filter.c @@ -828,12 +828,20 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, } filter->dst_id = vnic->fw_vnic_id; filter1 = bnxt_get_l2_filter(bp, filter, vnic); + if (filter1 == NULL) { + rc = -ENOSPC; + goto ret; + } filter->fw_l2_filter_id = filter1->fw_l2_filter_id; RTE_LOG(DEBUG, PMD, "VNIC found\n"); break; case RTE_FLOW_ACTION_TYPE_DROP: vnic0 = STAILQ_FIRST(&bp->ff_pool[0]); filter1 = bnxt_get_l2_filter(bp, filter, vnic0); + if (filter1 == NULL) { + rc = -ENOSPC; + goto ret; + } filter->fw_l2_filter_id = filter1->fw_l2_filter_id; if (filter->filter_type == HWRM_CFA_EM_FILTER) filter->flags = @@ -845,6 +853,10 @@ bnxt_validate_and_parse_flow(struct rte_eth_dev *dev, case RTE_FLOW_ACTION_TYPE_COUNT: vnic0 = STAILQ_FIRST(&bp->ff_pool[0]); filter1 = bnxt_get_l2_filter(bp, filter, vnic0); + if (filter1 == NULL) { + rc = -ENOSPC; + goto ret; + } filter->fw_l2_filter_id = filter1->fw_l2_filter_id; filter->flags = HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_FLAGS_METER; break; @@ -892,6 +904,7 @@ bnxt_flow_validate(struct rte_eth_dev *dev, ret = bnxt_validate_and_parse_flow(dev, pattern, actions, attr, error, filter); /* No need to hold on to this filter if we are just validating flow */ + filter->fw_l2_filter_id = -1; bnxt_free_filter(bp, filter); return ret; @@ -961,6 +974,7 @@ bnxt_flow_create(struct rte_eth_dev *dev, return flow; } free_filter: + filter->fw_l2_filter_id = -1; bnxt_free_filter(bp, filter); free_flow: RTE_LOG(ERR, PMD, "Failed to create flow.\n"); -- 2.20.1