[dpdk-dev,v2,01/18] lib/libtre_table: workaround hash function cast error

Message ID 152582945575.6809.1197897366448536704.stgit@localhost.localdomain (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Andy Green May 9, 2018, 1:30 a.m. UTC
  /home/agreen/projects/dpdk/lib/librte_table/rte_table_hash_cuckoo.c:
110:16: error: cast between incompatible function types from
‘rte_table_hash_op_hash’ {aka ‘long unsigned int (*)(void *, void *,
unsigned int,  long unsigned int)’} to ‘uint32_t (*)(const void *,
uint32_t,  uint32_t)’ {aka ‘unsigned int (*)(const void *, unsigned
int,  unsigned int)’} [-Werror=cast-function-type]   .hash_func =
(rte_hash_function)(p->f_hash),

The code seems to be quite broken.

It's casting this

typedef uint64_t (*rte_table_hash_op_hash)(
        void *key,
        void *key_mask,
        uint32_t key_size,
        uint64_t seed);

to this

typedef uint32_t (*rte_hash_function)(const void *key, uint32_t key_len,
                                      uint32_t init_val);

if the definition with 4 args is later called with a pointer
giving it three args, obviously it working is just an accident.  I
grepped around a bit and could not see it being cast back to
the original type before use; the uses I saw have three args.

I simply patch it to stop the build breaking, rather than fix it,
since I am not sure what a fix should look like considering the
whole code.

(It seems others are working on fixing this, so you probably don't
want to apply this.  However it's necessary for build to continue atm)

Signed-off-by: Andy Green <andy@warmcat.com>
---
 lib/librte_table/rte_table_hash_cuckoo.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/lib/librte_table/rte_table_hash_cuckoo.c b/lib/librte_table/rte_table_hash_cuckoo.c
index dcb4fe978..eca72b506 100644
--- a/lib/librte_table/rte_table_hash_cuckoo.c
+++ b/lib/librte_table/rte_table_hash_cuckoo.c
@@ -107,7 +107,7 @@  rte_table_hash_cuckoo_create(void *params,
 	struct rte_hash_parameters hash_cuckoo_params = {
 		.entries = p->n_keys,
 		.key_len = p->key_size,
-		.hash_func = (rte_hash_function)(p->f_hash),
+		.hash_func = (rte_hash_function)(void *)(p->f_hash),
 		.hash_func_init_val = p->seed,
 		.socket_id = socket_id,
 		.name = p->name