Skip to contentSkip to conversation

net/mlx5: HWS, Add error checking to hws_bwc_rule_complex_hash_node_get()

PATCH Applied Dan Carpenter 3 participants 3 messages Jun 11, 2025 – Jun 12, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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 17e0accac577 ("net/mlx5: HWS, support complex matchers")

---
v2: Add error checking for ida_alloc() and add cleanup.

 .../mlx5/core/steering/hws/bwc_complex.c      | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +17 -2
index 70768953a4f6..ca7501c57468 100644
@@ -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
Signature · 1 line
2.47.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 51 lines · Dan Carpenter

Check for if ida_alloc() or rhashtable_lookup_get_insert_fast() fails.

Fixes 17e0accac577 ("net/mlx5: HWS, support complex matchers")

---
v2: Add error checking for ida_alloc() and add cleanup.

  .../mlx5/core/steering/hws/bwc_complex.c      | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +11 -2
index 70768953a4f6..ca7501c57468 100644
@@ -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;

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c hws_bwc_rule_complex_hash_node_get(struct mlx5hws_bwc_rule *bwc_rule, · line 1132

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +6 -0
  	return 0;
+
+err_free_ida:
+	ida_free(&bwc_matcher->complex->metadata_ida, node->tag);
+err_free_node:
+	kfree(node);
+	return ret;
  }
 
  static void

Thanks Dan

#2 lore raw
In reply to Dan Carpenter
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 11 Jun 2025 16:14:32 +0300 you wrote:

Check for if ida_alloc() or rhashtable_lookup_get_insert_fast() fails.

Fixes 17e0accac577 ("net/mlx5: HWS, support complex matchers")

---
v2: Add error checking for ida_alloc() and add cleanup.

[...]

Here is the summary with links:
- [v2,net] net/mlx5: HWS, Add error checking to hws_bwc_rule_complex_hash_node_get()

    https://git.kernel.org/netdev/net/c/1619bdf4389c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html