Commit 84dfac39 authored by Yevgeny Kliteynik's avatar Yevgeny Kliteynik Committed by Saeed Mahameed

net/mlx5: DR, Fix error flow in creating matcher

The error code of nic matcher init functions wasn't checked.
This patch improves the matcher init function and fix error flow bug:
the handling of match parameter is moved into a separate function
and error flow is simplified.
Signed-off-by: default avatarYevgeny Kliteynik <kliteyn@nvidia.com>
parent af30f8ea
...@@ -872,13 +872,12 @@ static int dr_matcher_init_fdb(struct mlx5dr_matcher *matcher) ...@@ -872,13 +872,12 @@ static int dr_matcher_init_fdb(struct mlx5dr_matcher *matcher)
return ret; return ret;
} }
static int dr_matcher_init(struct mlx5dr_matcher *matcher, static int dr_matcher_copy_param(struct mlx5dr_matcher *matcher,
struct mlx5dr_match_parameters *mask) struct mlx5dr_match_parameters *mask)
{ {
struct mlx5dr_domain *dmn = matcher->tbl->dmn;
struct mlx5dr_match_parameters consumed_mask; struct mlx5dr_match_parameters consumed_mask;
struct mlx5dr_table *tbl = matcher->tbl; int i, ret = 0;
struct mlx5dr_domain *dmn = tbl->dmn;
int i, ret;
if (matcher->match_criteria >= DR_MATCHER_CRITERIA_MAX) { if (matcher->match_criteria >= DR_MATCHER_CRITERIA_MAX) {
mlx5dr_err(dmn, "Invalid match criteria attribute\n"); mlx5dr_err(dmn, "Invalid match criteria attribute\n");
...@@ -898,10 +897,36 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher, ...@@ -898,10 +897,36 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
consumed_mask.match_sz = mask->match_sz; consumed_mask.match_sz = mask->match_sz;
memcpy(consumed_mask.match_buf, mask->match_buf, mask->match_sz); memcpy(consumed_mask.match_buf, mask->match_buf, mask->match_sz);
mlx5dr_ste_copy_param(matcher->match_criteria, mlx5dr_ste_copy_param(matcher->match_criteria,
&matcher->mask, &consumed_mask, &matcher->mask, &consumed_mask, true);
true);
/* Check that all mask data was consumed */
for (i = 0; i < consumed_mask.match_sz; i++) {
if (!((u8 *)consumed_mask.match_buf)[i])
continue;
mlx5dr_dbg(dmn,
"Match param mask contains unsupported parameters\n");
ret = -EOPNOTSUPP;
break;
}
kfree(consumed_mask.match_buf);
} }
return ret;
}
static int dr_matcher_init(struct mlx5dr_matcher *matcher,
struct mlx5dr_match_parameters *mask)
{
struct mlx5dr_table *tbl = matcher->tbl;
struct mlx5dr_domain *dmn = tbl->dmn;
int ret;
ret = dr_matcher_copy_param(matcher, mask);
if (ret)
return ret;
switch (dmn->type) { switch (dmn->type) {
case MLX5DR_DOMAIN_TYPE_NIC_RX: case MLX5DR_DOMAIN_TYPE_NIC_RX:
matcher->rx.nic_tbl = &tbl->rx; matcher->rx.nic_tbl = &tbl->rx;
...@@ -919,22 +944,8 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher, ...@@ -919,22 +944,8 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
default: default:
WARN_ON(true); WARN_ON(true);
ret = -EINVAL; ret = -EINVAL;
goto free_consumed_mask;
}
/* Check that all mask data was consumed */
for (i = 0; i < consumed_mask.match_sz; i++) {
if (!((u8 *)consumed_mask.match_buf)[i])
continue;
mlx5dr_dbg(dmn, "Match param mask contains unsupported parameters\n");
ret = -EOPNOTSUPP;
goto free_consumed_mask;
} }
ret = 0;
free_consumed_mask:
kfree(consumed_mask.match_buf);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment