Skip to contentSkip to conversation

hash: separate param checks in hash create func

PATCH Superseded Niall Meade 4 participants 12 messages Jul 30, 2024 – Oct 18, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hash: separate param checks in hash create func

Separated name, entries and key_len parameter checks in rte_hash_create(). Also made the error messages more informative/verbose to help with debugging. Also added myself to the mailing list.

---

I had name set to NULL in the parameters I was passing to rte_hash_create() and the error message I got didn't specify which parameter was invalid.

---
 .mailmap                   |  1 +
 lib/hash/rte_cuckoo_hash.c | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)
.mailmap +1 -0
index 8aef1c59a4..e2a1d55203 100644
@@ -1054,6 +1054,7 @@ Nelson Escobar <[email protected]>
 Nemanja Marjanovic <[email protected]>
 Netanel Belgazal <[email protected]>
 Netanel Gonen <[email protected]>
+Niall Meade <[email protected]>
 Niall Power <[email protected]>
 Nicholas Pratte <[email protected]>
 Nick Connolly <[email protected]> <[email protected]>
lib/hash/rte_cuckoo_hash.c +18 -4
index 577b5839d3..97d55ca23b 100644
@@ -190,11 +190,18 @@ rte_hash_create(const struct rte_hash_parameters *params)
 
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
 		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s has invalid parameters, entries must be "
+		 "in the range %d to %d inclusive", __func__,
+		  RTE_HASH_BUCKET_ENTRIES, RTE_HASH_ENTRIES_MAX);
+		return NULL;
+	}
+
+	if (params->key_len == 0) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s has invalid parameters, key_len must be "
+		 "greater than 0", __func__);
 		return NULL;
 	}
 
@@ -204,6 +211,13 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->name == NULL) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s has invalid parameters, name can't be NULL",
+			__func__);
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 13 lines
2.34.1

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
Acked-by on v1 1/1
#1 lore raw
Quoted 70 lines · Niall Meade

Separated name, entries and key_len parameter checks in rte_hash_create(). Also made the error messages more informative/verbose to help with debugging. Also added myself to the mailing list.

---

I had name set to NULL in the parameters I was passing to rte_hash_create() and the error message I got didn't specify which parameter was invalid.

---
  .mailmap                   |  1 +
  lib/hash/rte_cuckoo_hash.c | 22 ++++++++++++++++++----
  2 files changed, 19 insertions(+), 4 deletions(-)
.mailmap +1 -0
index 8aef1c59a4..e2a1d55203 100644
@@ -1054,6 +1054,7 @@ Nelson Escobar <[email protected]>
  Nemanja Marjanovic <[email protected]>
  Netanel Belgazal <[email protected]>
  Netanel Gonen <[email protected]>
+Niall Meade <[email protected]>
  Niall Power <[email protected]>
  Nicholas Pratte <[email protected]>
  Nick Connolly <[email protected]> <[email protected]>
lib/hash/rte_cuckoo_hash.c +18 -4
index 577b5839d3..97d55ca23b 100644
@@ -190,11 +190,18 @@ rte_hash_create(const struct rte_hash_parameters *params)
 
  	/* Check for valid parameters */
  	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
  		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s has invalid parameters, entries must be "
+		 "in the range %d to %d inclusive", __func__,
+		  RTE_HASH_BUCKET_ENTRIES, RTE_HASH_ENTRIES_MAX);
+		return NULL;
+	}
+
+	if (params->key_len == 0) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s has invalid parameters, key_len must be "
+		 "greater than 0", __func__);
  		return NULL;
  	}
 
@@ -204,6 +211,13 @@ rte_hash_create(const struct rte_hash_parameters *params)
  		return NULL;
  	}
 
+	if (params->name == NULL) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s has invalid parameters, name can't be NULL",
+			__func__);
+		return NULL;
+	}
+
  	/* Validate correct usage of extra options */
  	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
  	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 2 lines
Regards,
Vladimir
#2 lore raw
In reply to Niall Meade

lib/hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 197

Quoted 4 lines · On Fri, 26 Jul 2024 14:54:43 +0000 Niall Meade <[email protected]> wrote:
lib/hash/rte_cuckoo_hash.c +3 -1
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s has invalid parameters, entries must be "
+		 "in the range %d to %d inclusive", __func__,
+		  RTE_HASH_BUCKET_ENTRIES, RTE_HASH_ENTRIES_MAX);

Suggest shorter wording and don't break messages across lines, it makes it harder for the user to search for them. Suggest messages like:

		HASH_LOG(ERR, "%s() %u entries outside of range [%u..%u]",
			__func__, params->entries, 
			RTE_HASH_BUCKET_ENTRIES, RTE_HASH_ENTRIES_MAX);

Shorter is better.

#3 lore raw

PATCH v2 1/1 hash: separate param checks in hash create func

In reply to Niall Meade

Separated name, entries and key_len parameter checks in rte_hash_create(). Also made the error messages more informative/verbose to help with debugging. Also added myself to the mailing list.

---
v2:
* change hash log messages to be one line

I had name set to NULL in the parameters I was passing to rte_hash_create() and the error message I got didn't specify which parameter was invalid.

---
 .mailmap                   |  1 +
 lib/hash/rte_cuckoo_hash.c | 21 +++++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)
.mailmap +1 -0
index a66da3c8cb..93df2effb2 100644
@@ -1055,6 +1055,7 @@ Nelson Escobar <[email protected]>
 Nemanja Marjanovic <[email protected]>
 Netanel Belgazal <[email protected]>
 Netanel Gonen <[email protected]>
+Niall Meade <[email protected]>
 Niall Power <[email protected]>
 Nicholas Pratte <[email protected]>
 Nick Connolly <[email protected]> <[email protected]>
lib/hash/rte_cuckoo_hash.c +17 -4
index 577b5839d3..2569f7d977 100644
@@ -190,11 +190,17 @@ rte_hash_create(const struct rte_hash_parameters *params)
 
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
 		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s() entries (%u) must be in range [%d, %d] inclusive",
+		__func__, params->entries, RTE_HASH_BUCKET_ENTRIES,
+		RTE_HASH_ENTRIES_MAX);
+		return NULL;
+	}
+
+	if (params->key_len == 0) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() key_len must be greater than 0", __func__);
 		return NULL;
 	}
 
@@ -204,6 +210,13 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->name == NULL) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() has invalid parameters, name can't be NULL",
+			__func__);
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 13 lines
2.34.1

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
Registered Number: 308263


This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient(s). Any review or distribution by others is
strictly prohibited. If you are not the intended recipient, please contact the
sender and delete all copies.
#4 lore raw
Quoted 11 lines · On Thu, 10 Oct 2024 16:46:02 +0000 Niall Meade <[email protected]> wrote:

--------------------------------------------------------------
Intel Research and Development Ireland Limited
Registered in Ireland
Registered Office: Collinstown Industrial Park, Leixlip, County Kildare Registered Number: 308263

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Fix your lawyer footer. Technically any patches sent to public mailing lists would have to be legally dropped.

#5 lore raw
In reply to Niall Meade
Quoted 7 lines · On Thu, 10 Oct 2024 16:46:02 +0000 Niall Meade <[email protected]> wrote:
lib/hash/rte_cuckoo_hash.c +0 -0
index 577b5839d3..2569f7d977 100644
@@ -190,11 +190,17 @@ rte_hash_create(const struct rte_hash_parameters *params)
 
 	/* Check for valid parameters */

lib/hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 197

Quoted 10 lines
lib/hash/rte_cuckoo_hash.c +4 -4
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
 		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s() entries (%u) must be in range [%d, %d] inclusive",
+		__func__, params->entries, RTE_HASH_BUCKET_ENTRIES,
+		RTE_HASH_ENTRIES_MAX);

Need to indent function args here.

lib/hash/rte_cuckoo_hash.c rte_hash_create(const struct rte_hash_parameters *params) · line 199

Quoted 2 lines
lib/hash/rte_cuckoo_hash.c +2 -0
+		return NULL;
+	}

Noticed this function is inconstitent about setting rte_errno. Not sure if it matters.

#6 lore raw

PATCH v3 1/1 hash: separate param checks in hash create func

In reply to Niall Meade

Separated name, entries and key_len parameter checks in rte_hash_create(). Also made the error messages more informative/verbose to help with debugging. Also added myself to the mailing list.

---
v3:
* code indentation fix and rte_errno set correctly v2:
* change hash log messages to be one line

I had name set to NULL in the parameters I was passing to rte_hash_create() and the error message I got didn't specify which parameter was invalid.

---
 .mailmap                   |  1 +
 lib/hash/rte_cuckoo_hash.c | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)
.mailmap +1 -0
index a66da3c8cb..93df2effb2 100644
@@ -1055,6 +1055,7 @@ Nelson Escobar <[email protected]>
 Nemanja Marjanovic <[email protected]>
 Netanel Belgazal <[email protected]>
 Netanel Gonen <[email protected]>
+Niall Meade <[email protected]>
 Niall Power <[email protected]>
 Nicholas Pratte <[email protected]>
 Nick Connolly <[email protected]> <[email protected]>
lib/hash/rte_cuckoo_hash.c +18 -4
index 577b5839d3..9575e8aa0c 100644
@@ -184,17 +184,24 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list);
 
 	if (params == NULL) {
+		rte_errno = EINVAL;
 		HASH_LOG(ERR, "%s has no parameters", __func__);
 		return NULL;
 	}
 
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() entries (%u) must be in range [%d, %d] inclusive",
+			__func__, params->entries, RTE_HASH_BUCKET_ENTRIES,
+			RTE_HASH_ENTRIES_MAX);
+		return NULL;
+	}
+
+	if (params->key_len == 0) {
 		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s() key_len must be greater than 0", __func__);
 		return NULL;
 	}
 
@@ -204,6 +211,13 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->name == NULL) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() has invalid parameters, name can't be NULL",
+			__func__);
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 1 line
2.34.1
#9 lore raw

PATCH v4 1/1 hash: separate creation parameters checks

In reply to Niall Meade

From: Niall Meade <[email protected]>

Separate name, entries and key_len parameter checks in rte_hash_create(). Also make the error messages more informative/verbose
to help with debugging.

---
v4: formatting details
sent for triggering a new CI run

---
 lib/hash/rte_cuckoo_hash.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
lib/hash/rte_cuckoo_hash.c +18 -4
index 577b5839d3..9575e8aa0c 100644
@@ -184,17 +184,24 @@ rte_hash_create(const struct rte_hash_parameters *params)
 	hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list);
 
 	if (params == NULL) {
+		rte_errno = EINVAL;
 		HASH_LOG(ERR, "%s has no parameters", __func__);
 		return NULL;
 	}
 
 	/* Check for valid parameters */
 	if ((params->entries > RTE_HASH_ENTRIES_MAX) ||
-			(params->entries < RTE_HASH_BUCKET_ENTRIES) ||
-			(params->name == NULL) ||
-			(params->key_len == 0)) {
+			(params->entries < RTE_HASH_BUCKET_ENTRIES)) {
 		rte_errno = EINVAL;
-		HASH_LOG(ERR, "%s has invalid parameters", __func__);
+		HASH_LOG(ERR, "%s() entries (%u) must be in range [%d, %d] inclusive",
+			__func__, params->entries, RTE_HASH_BUCKET_ENTRIES,
+			RTE_HASH_ENTRIES_MAX);
+		return NULL;
+	}
+
+	if (params->key_len == 0) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() key_len must be greater than 0", __func__);
 		return NULL;
 	}
 
@@ -204,6 +211,13 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->name == NULL) {
+		rte_errno = EINVAL;
+		HASH_LOG(ERR, "%s() has invalid parameters, name can't be NULL",
+			__func__);
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 1 line
2.46.0
#10 lore raw

Re: [PATCH v4] hash: separate creation parameters checks

17/10/2024 17:10, Thomas Monjalon:

Quoted 11 lines

From: Niall Meade <[email protected]>

Separate name, entries and key_len parameter checks in rte_hash_create(). Also make the error messages more informative/verbose
to help with debugging.

---
v4: formatting details
sent for triggering a new CI run

The community CI lab is not in a good shape today
but I take the risk applying this patch.

#11 lore raw

Re: [PATCH v4] hash: separate creation parameters checks

Quoted 7 lines

17/10/2024 17:10, Thomas Monjalon:

Quoted 6 lines

From: Niall Meade <[email protected]>

Separate name, entries and key_len parameter checks in rte_hash_create(). Also make the error messages more informative/verbose
to help with debugging.

Quoted 8 lines
Quoted 5 lines

---
v4: formatting details
sent for triggering a new CI run

The community CI lab is not in a good shape today
but I take the risk applying this patch.

Thanks Thomas