Commit 1619bdf4 authored by Dan Carpenter's avatar Dan Carpenter Committed by Jakub Kicinski
Browse files

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: 17e0acca ("net/mlx5: HWS, support complex matchers")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarYevgeny Kliteynik <kliteyn@nvidia.com>
Link: https://patch.msgid.link/aEmBONjyiF6z5yCV@stanley.mountain


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 9337c544
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -1070,7 +1070,7 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,
	struct mlx5hws_bwc_matcher *bwc_matcher = bwc_rule->bwc_matcher;
	struct mlx5hws_bwc_complex_rule_hash_node *node, *old_node;
	struct rhashtable *refcount_hash;
	int i;
	int ret, i;

	bwc_rule->complex_hash_node = NULL;

@@ -1078,7 +1078,11 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,
	if (unlikely(!node))
		return -ENOMEM;

	node->tag = ida_alloc(&bwc_matcher->complex->metadata_ida, GFP_KERNEL);
	ret = ida_alloc(&bwc_matcher->complex->metadata_ida, GFP_KERNEL);
	if (ret < 0)
		goto err_free_node;
	node->tag = ret;

	refcount_set(&node->refcount, 1);

	/* 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,
	old_node = rhashtable_lookup_get_insert_fast(refcount_hash,
						     &node->hash_node,
						     hws_refcount_hash);
	if (IS_ERR(old_node)) {
		ret = PTR_ERR(old_node);
		goto err_free_ida;
	}

	if (old_node) {
		/* Rule with the same tag already exists - update refcount */
		refcount_inc(&old_node->refcount);
@@ -1112,6 +1121,12 @@ hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule,

	bwc_rule->complex_hash_node = node;
	return 0;

err_free_ida:
	ida_free(&bwc_matcher->complex->metadata_ida, node->tag);
err_free_node:
	kfree(node);
	return ret;
}

static void