net/bnxt: fix cleanup if a filter allocation fails
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Tue, 10 Oct 2017 14:23:00 +0000 (09:23 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 12 Oct 2017 00:52:49 +0000 (01:52 +0100)
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 <ajit.khaparde@broadcom.com>
drivers/net/bnxt/bnxt_filter.c

index 9f171fd..4c1db55 100644 (file)
@@ -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");