Skip to content

Commit

Permalink
net/hns3: fix flow director rule residue on malloc failure
Browse files Browse the repository at this point in the history
[ upstream commit 2b9a66e ]

After FD rule config success, driver will malloc fdir_rule to hold the
rule info, if malloc fail the FD rule in hardware was not cleanup.

Fixes: fcba820 ("net/hns3: support flow director")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
  • Loading branch information
fengchengwen authored and bluca committed Feb 8, 2021
1 parent 5e0908d commit ffb6a48
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions drivers/net/hns3/hns3_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,17 +1822,18 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,

flow->counter_id = fdir_rule.act_cnt.id;
}

fdir_rule_ptr = rte_zmalloc("hns3 fdir rule",
sizeof(struct hns3_fdir_rule_ele),
0);
if (fdir_rule_ptr == NULL) {
hns3_err(hw, "failed to allocate fdir_rule memory.");
ret = -ENOMEM;
goto err_fdir;
}

ret = hns3_fdir_filter_program(hns, &fdir_rule, false);
if (!ret) {
fdir_rule_ptr = rte_zmalloc("hns3 fdir rule",
sizeof(struct hns3_fdir_rule_ele),
0);
if (fdir_rule_ptr == NULL) {
hns3_err(hw, "Failed to allocate fdir_rule memory");
ret = -ENOMEM;
goto err_fdir;
}

memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule,
sizeof(struct hns3_fdir_rule));
TAILQ_INSERT_TAIL(&process_list->fdir_list,
Expand All @@ -1843,10 +1844,10 @@ hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
return flow;
}

rte_free(fdir_rule_ptr);
err_fdir:
if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
hns3_counter_release(dev, fdir_rule.act_cnt.id);

err:
rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
"Failed to create flow");
Expand Down

0 comments on commit ffb6a48

Please sign in to comment.