Skip to contentSkip to conversation

net/mlx5: HWS, Add an error check in hws_bwc_rule_complex_hash_node_get()

PATCH In review Dan Carpenter 2 participants 3 messages May 28, 2025 – Jun 2, 2025

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

PATCH 1/1 net/mlx5: HWS, Add an error check in hws_bwc_rule_complex_hash_node_get()

The rhashtable_lookup_get_insert_fast() function inserts an object into the hashtable. If the object was already present in the table it returns a pointer to the original object. If the object wasn't there it returns NULL. If there was an allocation error or some other kind of failure, it returns an error pointer.

This caller needs to check for error pointers to avoid an error pointer dereference. Add the check.

Fixes 17e0accac577 ("net/mlx5: HWS, support complex matchers")
---
 .../net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +3 -0
index 5d30c5b094fc..6ae362fe2f36 100644
@@ -1094,6 +1094,9 @@ 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))
+		return PTR_ERR(old_node);
+
 	if (old_node) {
 		/* Rule with the same tag already exists - update refcount */
 		refcount_inc(&old_node->refcount);
Signature · 1 line
2.47.2
#1 lore raw
Quoted 20 lines · Dan Carpenter

The rhashtable_lookup_get_insert_fast() function inserts an object into the hashtable. If the object was already present in the table it returns a pointer to the original object. If the object wasn't there it returns NULL. If there was an allocation error or some other kind of failure, it returns an error pointer.

This caller needs to check for error pointers to avoid an error pointer dereference. Add the check.

Fixes 17e0accac577 ("net/mlx5: HWS, support complex matchers")
---
  .../net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +0 -0
index 5d30c5b094fc..6ae362fe2f36 100644

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 1099

Quoted 6 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +3 -0
@@ -1094,6 +1094,9 @@ 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))
+		return PTR_ERR(old_node);
+

Agree with the need to check IS_ERR, but error flow is missing here. Need to free the previously allocated IDA and node.

-- YK

Quoted 3 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +0 -0
  	if (old_node) {
  		/* Rule with the same tag already exists - update refcount */
  		refcount_inc(&old_node->refcount);
#2 lore raw
Quoted 16 lines · Yevgeny Kliteynik
Quoted 15 lines · Dan Carpenter

The rhashtable_lookup_get_insert_fast() function inserts an object into the hashtable. If the object was already present in the table it returns a pointer to the original object. If the object wasn't there it returns NULL. If there was an allocation error or some other kind of failure, it returns an error pointer.

This caller needs to check for error pointers to avoid an error pointer dereference. Add the check.

Fixes 17e0accac577 ("net/mlx5: HWS, support complex matchers")
---
  .../net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 15 lines

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 1099

Quoted 11 lines
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc_complex.c +3 -0
index 5d30c5b094fc..6ae362fe2f36 100644
@@ -1094,6 +1094,9 @@ 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))
+		return PTR_ERR(old_node);
+

Agree with the need to check IS_ERR, but error flow is missing here. Need to free the previously allocated IDA and node.

:/ Yeah. Sorry... I'll resend.

regards,
dan carpenter