net/hinic: check memory allocations in flow creation
authorYunjian Wang <wangyunjian@huawei.com>
Tue, 28 Jul 2020 12:34:46 +0000 (20:34 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 29 Jul 2020 22:41:23 +0000 (00:41 +0200)
The function rte_zmalloc() could return NULL, the return
value need to be checked.

Fixes: f4ca3fd54c4d ("net/hinic: create and destroy flow director filter")
Cc: stable@dpdk.org
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
drivers/net/hinic/hinic_pmd_flow.c

index a7bad57..503a32f 100644 (file)
@@ -2977,6 +2977,10 @@ static struct rte_flow *hinic_flow_create(struct rte_eth_dev *dev,
                if (!ret) {
                        ntuple_filter_ptr = rte_zmalloc("hinic_ntuple_filter",
                                sizeof(struct hinic_ntuple_filter_ele), 0);
+                       if (ntuple_filter_ptr == NULL) {
+                               PMD_DRV_LOG(ERR, "Failed to allocate ntuple_filter_ptr");
+                               goto out;
+                       }
                        rte_memcpy(&ntuple_filter_ptr->filter_info,
                                   &ntuple_filter,
                                   sizeof(struct rte_eth_ntuple_filter));
@@ -3003,6 +3007,10 @@ static struct rte_flow *hinic_flow_create(struct rte_eth_dev *dev,
                        ethertype_filter_ptr =
                                rte_zmalloc("hinic_ethertype_filter",
                                sizeof(struct hinic_ethertype_filter_ele), 0);
+                       if (ethertype_filter_ptr == NULL) {
+                               PMD_DRV_LOG(ERR, "Failed to allocate ethertype_filter_ptr");
+                               goto out;
+                       }
                        rte_memcpy(&ethertype_filter_ptr->filter_info,
                                &ethertype_filter,
                                sizeof(struct rte_eth_ethertype_filter));
@@ -3036,6 +3044,10 @@ static struct rte_flow *hinic_flow_create(struct rte_eth_dev *dev,
                if (!ret) {
                        fdir_rule_ptr = rte_zmalloc("hinic_fdir_rule",
                                sizeof(struct hinic_fdir_rule_ele), 0);
+                       if (fdir_rule_ptr == NULL) {
+                               PMD_DRV_LOG(ERR, "Failed to allocate fdir_rule_ptr");
+                               goto out;
+                       }
                        rte_memcpy(&fdir_rule_ptr->filter_info, &fdir_rule,
                                sizeof(struct hinic_fdir_rule));
                        TAILQ_INSERT_TAIL(&nic_dev->filter_fdir_rule_list,