]> git.droids-corp.org - dpdk.git/commitdiff
hash: validate hash bucket entries while compiling
authorHonnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Thu, 31 May 2018 15:30:49 +0000 (10:30 -0500)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 12 Jul 2018 10:43:10 +0000 (12:43 +0200)
Validate RTE_HASH_BUCKET_ENTRIES during compilation instead of
run time.

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
lib/librte_eal/common/include/rte_common.h
lib/librte_hash/rte_cuckoo_hash.c
lib/librte_hash/rte_cuckoo_hash.h

index 434adfd455e8e602851f3afccb5a1694c6198f6d..a9df7c161ad8e4fe73cc16456cb18e0da572ee78 100644 (file)
@@ -293,6 +293,11 @@ rte_combine64ms1b(register uint64_t v)
 
 /*********** Macros to work with powers of 2 ********/
 
+/**
+ * Macro to return 1 if n is a power of 2, 0 otherwise
+ */
+#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
+
 /**
  * Returns true if n is a power of 2
  * @param n
index a07543a29a522ecaa304c942db3103641ffddd36..375e7d208aeb077be0a5a6a4df12febe4ae1e491 100644 (file)
@@ -107,7 +107,6 @@ 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) ||
-                       !rte_is_power_of_2(RTE_HASH_BUCKET_ENTRIES) ||
                        (params->key_len == 0)) {
                rte_errno = EINVAL;
                RTE_LOG(ERR, HASH, "rte_hash_create has invalid parameters\n");
index 7a54e55575f17d9294bbe4d90643e4413e9c89a8..bd6ad1bd66703f6a00aaa261326da46771e6a335 100644 (file)
@@ -97,6 +97,10 @@ enum add_key_case {
 /** Number of items per bucket. */
 #define RTE_HASH_BUCKET_ENTRIES                8
 
+#if !RTE_IS_POWER_OF_2(RTE_HASH_BUCKET_ENTRIES)
+#error RTE_HASH_BUCKET_ENTRIES must be a power of 2
+#endif
+
 #define NULL_SIGNATURE                 0
 
 #define EMPTY_SLOT                     0