[PATCH v2 1/5] test: fix jhash 32 bit key type
Stephen Hemminger
stephen at networkplumber.org
Sun Sep 6 19:09:54 CEST 2026
verify_jhash_32bits() declares the key as an array of bytes, then
casts it to unaligned_uint32_t * to pass to rte_jhash_32b(), which
takes a const uint32_t *. Clang reports:
passing 1-byte aligned argument to 4-byte aligned parameter 1 of
'rte_jhash_32b' may result in an unaligned pointer access
[-Walign-mismatch]
This already happens on armv8 aarch32, where unaligned types have
alignment 1, and will happen everywhere once that is true on all
architectures.
Declare the key as an array of uint32_t and drop the cast.
Fixes: 7621d6a8d0bd ("eal: add and use unaligned integer types")
Cc: stable at dpdk.org
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
---
app/test/test_hash_functions.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c
index 70820d1f19..fdff304d2b 100644
--- a/app/test/test_hash_functions.c
+++ b/app/test/test_hash_functions.c
@@ -185,12 +185,12 @@ verify_precalculated_hash_func_tests(void)
static int
verify_jhash_32bits(void)
{
- unsigned i, j;
- uint8_t key[64];
+ unsigned int i, j;
+ uint32_t key[16];
uint32_t hash, hash32;
- for (i = 0; i < 64; i++)
- key[i] = rand() & 0xff;
+ for (i = 0; i < RTE_DIM(key); i++)
+ key[i] = (uint32_t) rte_rand();
for (i = 0; i < RTE_DIM(hashtest_key_lens); i++) {
for (j = 0; j < RTE_DIM(hashtest_initvals); j++) {
@@ -199,9 +199,9 @@ verify_jhash_32bits(void)
hash = rte_jhash(key, hashtest_key_lens[i],
hashtest_initvals[j]);
/* Divide key length by 4 in rte_jhash for 32 bits */
- hash32 = rte_jhash_32b((const unaligned_uint32_t *)key,
- hashtest_key_lens[i] >> 2,
- hashtest_initvals[j]);
+ hash32 = rte_jhash_32b(key,
+ hashtest_key_lens[i] / sizeof(uint32_t),
+ hashtest_initvals[j]);
if (hash != hash32) {
printf("rte_jhash returns different value (0x%x)"
"than rte_jhash_32b (0x%x)\n",
--
2.53.0
More information about the dev
mailing list