diff options
author | Antonio Quartulli <ordex@autistici.org> | 2011-10-05 17:05:25 +0200 |
---|---|---|
committer | Sven Eckelmann <sven@narfation.org> | 2011-11-20 13:08:33 +0100 |
commit | c90681b8505946761b55d4981c9c3b56b3c4171b (patch) | |
tree | b260388317b5dc1f4a8c00493eea6ff30fb47652 /net/batman-adv/hash.h | |
parent | eb7e2a1e20488f91c7007caa080b83b8e4222572 (diff) | |
download | op-kernel-dev-c90681b8505946761b55d4981c9c3b56b3c4171b.zip op-kernel-dev-c90681b8505946761b55d4981c9c3b56b3c4171b.tar.gz |
batman-adv: fixed hash functions type to uint32_t instead of int
There are two reasons for this fix:
- the result of choose_orig() and vis_choose() is an index and therefore it can't
be negative. Hence it is correct to make the return type unsigned too.
- sizeof(int) may not be the same on ALL the architectures. Since we plan to use
choose_orig() as DHT hash function, we need to guarantee that, given the same
argument, the result is the same. Then it is correct to explicitly express
the size of the return type (and the second argument). Since the expected
length is currently 4, uint32_t is the most convenient choice.
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/hash.h')
-rw-r--r-- | net/batman-adv/hash.h | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h index d20aa71..4768717 100644 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@ -33,17 +33,17 @@ typedef int (*hashdata_compare_cb)(const struct hlist_node *, const void *); /* the hashfunction, should return an index * based on the key in the data of the first * argument and the size the second */ -typedef int (*hashdata_choose_cb)(const void *, int); +typedef uint32_t (*hashdata_choose_cb)(const void *, uint32_t); typedef void (*hashdata_free_cb)(struct hlist_node *, void *); struct hashtable_t { struct hlist_head *table; /* the hashtable itself with the buckets */ spinlock_t *list_locks; /* spinlock for each hash list entry */ - int size; /* size of hashtable */ + uint32_t size; /* size of hashtable */ }; /* allocates and clears the hash */ -struct hashtable_t *hash_new(int size); +struct hashtable_t *hash_new(uint32_t size); /* free only the hashtable and the hash itself. */ void hash_destroy(struct hashtable_t *hash); @@ -57,7 +57,7 @@ static inline void hash_delete(struct hashtable_t *hash, struct hlist_head *head; struct hlist_node *node, *node_tmp; spinlock_t *list_lock; /* spinlock to protect write access */ - int i; + uint32_t i; for (i = 0; i < hash->size; i++) { head = &hash->table[i]; @@ -93,7 +93,8 @@ static inline int hash_add(struct hashtable_t *hash, hashdata_choose_cb choose, const void *data, struct hlist_node *data_node) { - int index, ret = -1; + uint32_t index; + int ret = -1; struct hlist_head *head; struct hlist_node *node; spinlock_t *list_lock; /* spinlock to protect write access */ @@ -137,7 +138,7 @@ static inline void *hash_remove(struct hashtable_t *hash, hashdata_compare_cb compare, hashdata_choose_cb choose, void *data) { - size_t index; + uint32_t index; struct hlist_node *node; struct hlist_head *head; void *data_save = NULL; |