Skip to content

Commit 1619bdf

Browse files
Dan Carpenterkuba-moo
authored andcommitted
net/mlx5: HWS, Add error checking to hws_bwc_rule_complex_hash_node_get()
Check for if ida_alloc() or rhashtable_lookup_get_insert_fast() fails. Fixes: 17e0acc ("net/mlx5: HWS, support complex matchers") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Yevgeny Kliteynik <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9337c54 commit 1619bdf

File tree

1 file changed

+17
-2
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core/steering/hws

1 file changed

+17
-2
lines changed

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,15 +1070,19 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,
10701070
struct mlx5hws_bwc_matcher *bwc_matcher = bwc_rule->bwc_matcher;
10711071
struct mlx5hws_bwc_complex_rule_hash_node *node, *old_node;
10721072
struct rhashtable *refcount_hash;
1073-
int i;
1073+
int ret, i;
10741074

10751075
bwc_rule->complex_hash_node = NULL;
10761076

10771077
node = kzalloc(sizeof(*node), GFP_KERNEL);
10781078
if (unlikely(!node))
10791079
return -ENOMEM;
10801080

1081-
node->tag = ida_alloc(&bwc_matcher->complex->metadata_ida, GFP_KERNEL);
1081+
ret = ida_alloc(&bwc_matcher->complex->metadata_ida, GFP_KERNEL);
1082+
if (ret < 0)
1083+
goto err_free_node;
1084+
node->tag = ret;
1085+
10821086
refcount_set(&node->refcount, 1);
10831087

10841088
/* Clear match buffer - turn off all the unrelated fields
@@ -1094,6 +1098,11 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,
10941098
old_node = rhashtable_lookup_get_insert_fast(refcount_hash,
10951099
&node->hash_node,
10961100
hws_refcount_hash);
1101+
if (IS_ERR(old_node)) {
1102+
ret = PTR_ERR(old_node);
1103+
goto err_free_ida;
1104+
}
1105+
10971106
if (old_node) {
10981107
/* Rule with the same tag already exists - update refcount */
10991108
refcount_inc(&old_node->refcount);
@@ -1112,6 +1121,12 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,
11121121

11131122
bwc_rule->complex_hash_node = node;
11141123
return 0;
1124+
1125+
err_free_ida:
1126+
ida_free(&bwc_matcher->complex->metadata_ida, node->tag);
1127+
err_free_node:
1128+
kfree(node);
1129+
return ret;
11151130
}
11161131

11171132
static void

0 commit comments

Comments
 (0)