mirror of
https://github.com/torvalds/linux.git
synced 2026-05-29 17:43:52 +02:00
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: Yevgeny Kliteynik <kliteyn@nvidia.com>
This commit is contained in:
parent
af30f8eaa8
commit
84dfac39c6
|
|
@ -872,13 +872,12 @@ static int dr_matcher_init_fdb(struct mlx5dr_matcher *matcher)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int dr_matcher_init(struct mlx5dr_matcher *matcher,
|
||||
struct mlx5dr_match_parameters *mask)
|
||||
static int dr_matcher_copy_param(struct mlx5dr_matcher *matcher,
|
||||
struct mlx5dr_match_parameters *mask)
|
||||
{
|
||||
struct mlx5dr_domain *dmn = matcher->tbl->dmn;
|
||||
struct mlx5dr_match_parameters consumed_mask;
|
||||
struct mlx5dr_table *tbl = matcher->tbl;
|
||||
struct mlx5dr_domain *dmn = tbl->dmn;
|
||||
int i, ret;
|
||||
int i, ret = 0;
|
||||
|
||||
if (matcher->match_criteria >= DR_MATCHER_CRITERIA_MAX) {
|
||||
mlx5dr_err(dmn, "Invalid match criteria attribute\n");
|
||||
|
|
@ -898,10 +897,36 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
|
|||
consumed_mask.match_sz = mask->match_sz;
|
||||
memcpy(consumed_mask.match_buf, mask->match_buf, mask->match_sz);
|
||||
mlx5dr_ste_copy_param(matcher->match_criteria,
|
||||
&matcher->mask, &consumed_mask,
|
||||
true);
|
||||
&matcher->mask, &consumed_mask, 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) {
|
||||
case MLX5DR_DOMAIN_TYPE_NIC_RX:
|
||||
matcher->rx.nic_tbl = &tbl->rx;
|
||||
|
|
@ -919,22 +944,8 @@ static int dr_matcher_init(struct mlx5dr_matcher *matcher,
|
|||
default:
|
||||
WARN_ON(true);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user