hash: separate param checks in hash create func

Message ID 20240726145443.1058676-1-niall.meade@intel.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series hash: separate param checks in hash create func |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Niall Meade July 26, 2024, 2:54 p.m. UTC
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.

Signed-off-by: Niall Meade <niall.meade@intel.com>

---

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(-)
  

Comments

Vladimir Medvedkin Sept. 4, 2024, 5:28 p.m. UTC | #1
Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

On 26/07/2024 15:54, Niall Meade wrote:
> 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.
>
> Signed-off-by: Niall Meade <niall.meade@intel.com>
>
> ---
>
> 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(-)
>
> diff --git a/.mailmap b/.mailmap
> index 8aef1c59a4..e2a1d55203 100644
> --- a/.mailmap
> +++ b/.mailmap
> @@ -1054,6 +1054,7 @@ Nelson Escobar <neescoba@cisco.com>
>   Nemanja Marjanovic <nemanja.marjanovic@intel.com>
>   Netanel Belgazal <netanel@amazon.com>
>   Netanel Gonen <netanelg@mellanox.com>
> +Niall Meade <niall.meade@intel.com>
>   Niall Power <niall.power@intel.com>
>   Nicholas Pratte <npratte@iol.unh.edu>
>   Nick Connolly <nick.connolly@arm.com> <nick.connolly@mayadata.io>
> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
> index 577b5839d3..97d55ca23b 100644
> --- a/lib/hash/rte_cuckoo_hash.c
> +++ b/lib/hash/rte_cuckoo_hash.c
> @@ -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)) {
  

Patch

diff --git a/.mailmap b/.mailmap
index 8aef1c59a4..e2a1d55203 100644
--- a/.mailmap
+++ b/.mailmap
@@ -1054,6 +1054,7 @@  Nelson Escobar <neescoba@cisco.com>
 Nemanja Marjanovic <nemanja.marjanovic@intel.com>
 Netanel Belgazal <netanel@amazon.com>
 Netanel Gonen <netanelg@mellanox.com>
+Niall Meade <niall.meade@intel.com>
 Niall Power <niall.power@intel.com>
 Nicholas Pratte <npratte@iol.unh.edu>
 Nick Connolly <nick.connolly@arm.com> <nick.connolly@mayadata.io>
diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 577b5839d3..97d55ca23b 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -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)) {