aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/hash.h
diff options
context:
space:
mode:
authorAntonio Quartulli <ordex@autistici.org>2011-10-05 11:05:25 -0400
committerSven Eckelmann <sven@narfation.org>2011-11-20 07:08:33 -0500
commitc90681b8505946761b55d4981c9c3b56b3c4171b (patch)
treeb260388317b5dc1f4a8c00493eea6ff30fb47652 /net/batman-adv/hash.h
parenteb7e2a1e20488f91c7007caa080b83b8e4222572 (diff)
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.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index d20aa71ba1e8..4768717f07f9 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 *);
33/* the hashfunction, should return an index 33/* the hashfunction, should return an index
34 * based on the key in the data of the first 34 * based on the key in the data of the first
35 * argument and the size the second */ 35 * argument and the size the second */
36typedef int (*hashdata_choose_cb)(const void *, int); 36typedef uint32_t (*hashdata_choose_cb)(const void *, uint32_t);
37typedef void (*hashdata_free_cb)(struct hlist_node *, void *); 37typedef void (*hashdata_free_cb)(struct hlist_node *, void *);
38 38
39struct hashtable_t { 39struct hashtable_t {
40 struct hlist_head *table; /* the hashtable itself with the buckets */ 40 struct hlist_head *table; /* the hashtable itself with the buckets */
41 spinlock_t *list_locks; /* spinlock for each hash list entry */ 41 spinlock_t *list_locks; /* spinlock for each hash list entry */
42 int size; /* size of hashtable */ 42 uint32_t size; /* size of hashtable */
43}; 43};
44 44
45/* allocates and clears the hash */ 45/* allocates and clears the hash */
46struct hashtable_t *hash_new(int size); 46struct hashtable_t *hash_new(uint32_t size);
47 47
48/* free only the hashtable and the hash itself. */ 48/* free only the hashtable and the hash itself. */
49void hash_destroy(struct hashtable_t *hash); 49void hash_destroy(struct hashtable_t *hash);
@@ -57,7 +57,7 @@ static inline void hash_delete(struct hashtable_t *hash,
57 struct hlist_head *head; 57 struct hlist_head *head;
58 struct hlist_node *node, *node_tmp; 58 struct hlist_node *node, *node_tmp;
59 spinlock_t *list_lock; /* spinlock to protect write access */ 59 spinlock_t *list_lock; /* spinlock to protect write access */
60 int i; 60 uint32_t i;
61 61
62 for (i = 0; i < hash->size; i++) { 62 for (i = 0; i < hash->size; i++) {
63 head = &hash->table[i]; 63 head = &hash->table[i];
@@ -93,7 +93,8 @@ static inline int hash_add(struct hashtable_t *hash,
93 hashdata_choose_cb choose, 93 hashdata_choose_cb choose,
94 const void *data, struct hlist_node *data_node) 94 const void *data, struct hlist_node *data_node)
95{ 95{
96 int index, ret = -1; 96 uint32_t index;
97 int ret = -1;
97 struct hlist_head *head; 98 struct hlist_head *head;
98 struct hlist_node *node; 99 struct hlist_node *node;
99 spinlock_t *list_lock; /* spinlock to protect write access */ 100 spinlock_t *list_lock; /* spinlock to protect write access */
@@ -137,7 +138,7 @@ static inline void *hash_remove(struct hashtable_t *hash,
137 hashdata_compare_cb compare, 138 hashdata_compare_cb compare,
138 hashdata_choose_cb choose, void *data) 139 hashdata_choose_cb choose, void *data)
139{ 140{
140 size_t index; 141 uint32_t index;
141 struct hlist_node *node; 142 struct hlist_node *node;
142 struct hlist_head *head; 143 struct hlist_head *head;
143 void *data_save = NULL; 144 void *data_save = NULL;