aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv
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
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')
-rw-r--r--net/batman-adv/hash.c4
-rw-r--r--net/batman-adv/hash.h13
-rw-r--r--net/batman-adv/originator.c13
-rw-r--r--net/batman-adv/originator.h2
-rw-r--r--net/batman-adv/routing.c2
-rw-r--r--net/batman-adv/translation-table.c32
-rw-r--r--net/batman-adv/vis.c17
7 files changed, 47 insertions, 36 deletions
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 2a172505f513..d1da29da333b 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -25,7 +25,7 @@
25/* clears the hash */ 25/* clears the hash */
26static void hash_init(struct hashtable_t *hash) 26static void hash_init(struct hashtable_t *hash)
27{ 27{
28 int i; 28 uint32_t i;
29 29
30 for (i = 0 ; i < hash->size; i++) { 30 for (i = 0 ; i < hash->size; i++) {
31 INIT_HLIST_HEAD(&hash->table[i]); 31 INIT_HLIST_HEAD(&hash->table[i]);
@@ -42,7 +42,7 @@ void hash_destroy(struct hashtable_t *hash)
42} 42}
43 43
44/* allocates and clears the hash */ 44/* allocates and clears the hash */
45struct hashtable_t *hash_new(int size) 45struct hashtable_t *hash_new(uint32_t size)
46{ 46{
47 struct hashtable_t *hash; 47 struct hashtable_t *hash;
48 48
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;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 0e5b77255d99..0bc2045a2f2e 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -164,7 +164,7 @@ void originator_free(struct bat_priv *bat_priv)
164 struct hlist_head *head; 164 struct hlist_head *head;
165 spinlock_t *list_lock; /* spinlock to protect write access */ 165 spinlock_t *list_lock; /* spinlock to protect write access */
166 struct orig_node *orig_node; 166 struct orig_node *orig_node;
167 int i; 167 uint32_t i;
168 168
169 if (!hash) 169 if (!hash)
170 return; 170 return;
@@ -350,7 +350,7 @@ static void _purge_orig(struct bat_priv *bat_priv)
350 struct hlist_head *head; 350 struct hlist_head *head;
351 spinlock_t *list_lock; /* spinlock to protect write access */ 351 spinlock_t *list_lock; /* spinlock to protect write access */
352 struct orig_node *orig_node; 352 struct orig_node *orig_node;
353 int i; 353 uint32_t i;
354 354
355 if (!hash) 355 if (!hash)
356 return; 356 return;
@@ -413,7 +413,8 @@ int orig_seq_print_text(struct seq_file *seq, void *offset)
413 int batman_count = 0; 413 int batman_count = 0;
414 int last_seen_secs; 414 int last_seen_secs;
415 int last_seen_msecs; 415 int last_seen_msecs;
416 int i, ret = 0; 416 uint32_t i;
417 int ret = 0;
417 418
418 primary_if = primary_if_get_selected(bat_priv); 419 primary_if = primary_if_get_selected(bat_priv);
419 420
@@ -519,7 +520,8 @@ int orig_hash_add_if(struct hard_iface *hard_iface, int max_if_num)
519 struct hlist_node *node; 520 struct hlist_node *node;
520 struct hlist_head *head; 521 struct hlist_head *head;
521 struct orig_node *orig_node; 522 struct orig_node *orig_node;
522 int i, ret; 523 uint32_t i;
524 int ret;
523 525
524 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on 526 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
525 * if_num */ 527 * if_num */
@@ -601,7 +603,8 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num)
601 struct hlist_head *head; 603 struct hlist_head *head;
602 struct hard_iface *hard_iface_tmp; 604 struct hard_iface *hard_iface_tmp;
603 struct orig_node *orig_node; 605 struct orig_node *orig_node;
604 int i, ret; 606 uint32_t i;
607 int ret;
605 608
606 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on 609 /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
607 * if_num */ 610 * if_num */
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h
index cfc1f60a96a1..67765ffef731 100644
--- a/net/batman-adv/originator.h
+++ b/net/batman-adv/originator.h
@@ -42,7 +42,7 @@ int orig_hash_del_if(struct hard_iface *hard_iface, int max_if_num);
42 42
43/* hashfunction to choose an entry in a hash table of given size */ 43/* hashfunction to choose an entry in a hash table of given size */
44/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */ 44/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
45static inline int choose_orig(const void *data, int32_t size) 45static inline uint32_t choose_orig(const void *data, uint32_t size)
46{ 46{
47 const unsigned char *key = data; 47 const unsigned char *key = data;
48 uint32_t hash = 0; 48 uint32_t hash = 0;
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index f961cc5eade5..60ce4077348b 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -39,7 +39,7 @@ void slide_own_bcast_window(struct hard_iface *hard_iface)
39 struct hlist_head *head; 39 struct hlist_head *head;
40 struct orig_node *orig_node; 40 struct orig_node *orig_node;
41 unsigned long *word; 41 unsigned long *word;
42 int i; 42 uint32_t i;
43 size_t word_index; 43 size_t word_index;
44 44
45 for (i = 0; i < hash->size; i++) { 45 for (i = 0; i < hash->size; i++) {
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 7ab9d72ce978..5f28a7f0b03e 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -67,7 +67,7 @@ static struct tt_local_entry *tt_local_hash_find(struct bat_priv *bat_priv,
67 struct hlist_head *head; 67 struct hlist_head *head;
68 struct hlist_node *node; 68 struct hlist_node *node;
69 struct tt_local_entry *tt_local_entry, *tt_local_entry_tmp = NULL; 69 struct tt_local_entry *tt_local_entry, *tt_local_entry_tmp = NULL;
70 int index; 70 uint32_t index;
71 71
72 if (!hash) 72 if (!hash)
73 return NULL; 73 return NULL;
@@ -99,7 +99,7 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv,
99 struct hlist_node *node; 99 struct hlist_node *node;
100 struct tt_global_entry *tt_global_entry; 100 struct tt_global_entry *tt_global_entry;
101 struct tt_global_entry *tt_global_entry_tmp = NULL; 101 struct tt_global_entry *tt_global_entry_tmp = NULL;
102 int index; 102 uint32_t index;
103 103
104 if (!hash) 104 if (!hash)
105 return NULL; 105 return NULL;
@@ -316,7 +316,8 @@ int tt_local_seq_print_text(struct seq_file *seq, void *offset)
316 struct hlist_head *head; 316 struct hlist_head *head;
317 size_t buf_size, pos; 317 size_t buf_size, pos;
318 char *buff; 318 char *buff;
319 int i, ret = 0; 319 uint32_t i;
320 int ret = 0;
320 321
321 primary_if = primary_if_get_selected(bat_priv); 322 primary_if = primary_if_get_selected(bat_priv);
322 if (!primary_if) { 323 if (!primary_if) {
@@ -427,7 +428,7 @@ static void tt_local_purge(struct bat_priv *bat_priv)
427 struct hlist_node *node, *node_tmp; 428 struct hlist_node *node, *node_tmp;
428 struct hlist_head *head; 429 struct hlist_head *head;
429 spinlock_t *list_lock; /* protects write access to the hash lists */ 430 spinlock_t *list_lock; /* protects write access to the hash lists */
430 int i; 431 uint32_t i;
431 432
432 for (i = 0; i < hash->size; i++) { 433 for (i = 0; i < hash->size; i++) {
433 head = &hash->table[i]; 434 head = &hash->table[i];
@@ -465,7 +466,7 @@ static void tt_local_table_free(struct bat_priv *bat_priv)
465 struct tt_local_entry *tt_local_entry; 466 struct tt_local_entry *tt_local_entry;
466 struct hlist_node *node, *node_tmp; 467 struct hlist_node *node, *node_tmp;
467 struct hlist_head *head; 468 struct hlist_head *head;
468 int i; 469 uint32_t i;
469 470
470 if (!bat_priv->tt_local_hash) 471 if (!bat_priv->tt_local_hash)
471 return; 472 return;
@@ -592,7 +593,8 @@ int tt_global_seq_print_text(struct seq_file *seq, void *offset)
592 struct hlist_head *head; 593 struct hlist_head *head;
593 size_t buf_size, pos; 594 size_t buf_size, pos;
594 char *buff; 595 char *buff;
595 int i, ret = 0; 596 uint32_t i;
597 int ret = 0;
596 598
597 primary_if = primary_if_get_selected(bat_priv); 599 primary_if = primary_if_get_selected(bat_priv);
598 if (!primary_if) { 600 if (!primary_if) {
@@ -716,7 +718,7 @@ void tt_global_del_orig(struct bat_priv *bat_priv,
716 struct orig_node *orig_node, const char *message) 718 struct orig_node *orig_node, const char *message)
717{ 719{
718 struct tt_global_entry *tt_global_entry; 720 struct tt_global_entry *tt_global_entry;
719 int i; 721 uint32_t i;
720 struct hashtable_t *hash = bat_priv->tt_global_hash; 722 struct hashtable_t *hash = bat_priv->tt_global_hash;
721 struct hlist_node *node, *safe; 723 struct hlist_node *node, *safe;
722 struct hlist_head *head; 724 struct hlist_head *head;
@@ -755,7 +757,7 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
755 struct hlist_node *node, *node_tmp; 757 struct hlist_node *node, *node_tmp;
756 struct hlist_head *head; 758 struct hlist_head *head;
757 spinlock_t *list_lock; /* protects write access to the hash lists */ 759 spinlock_t *list_lock; /* protects write access to the hash lists */
758 int i; 760 uint32_t i;
759 761
760 for (i = 0; i < hash->size; i++) { 762 for (i = 0; i < hash->size; i++) {
761 head = &hash->table[i]; 763 head = &hash->table[i];
@@ -789,7 +791,7 @@ static void tt_global_table_free(struct bat_priv *bat_priv)
789 struct tt_global_entry *tt_global_entry; 791 struct tt_global_entry *tt_global_entry;
790 struct hlist_node *node, *node_tmp; 792 struct hlist_node *node, *node_tmp;
791 struct hlist_head *head; 793 struct hlist_head *head;
792 int i; 794 uint32_t i;
793 795
794 if (!bat_priv->tt_global_hash) 796 if (!bat_priv->tt_global_hash)
795 return; 797 return;
@@ -875,7 +877,8 @@ uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node)
875 struct tt_global_entry *tt_global_entry; 877 struct tt_global_entry *tt_global_entry;
876 struct hlist_node *node; 878 struct hlist_node *node;
877 struct hlist_head *head; 879 struct hlist_head *head;
878 int i, j; 880 uint32_t i;
881 int j;
879 882
880 for (i = 0; i < hash->size; i++) { 883 for (i = 0; i < hash->size; i++) {
881 head = &hash->table[i]; 884 head = &hash->table[i];
@@ -912,7 +915,8 @@ uint16_t tt_local_crc(struct bat_priv *bat_priv)
912 struct tt_local_entry *tt_local_entry; 915 struct tt_local_entry *tt_local_entry;
913 struct hlist_node *node; 916 struct hlist_node *node;
914 struct hlist_head *head; 917 struct hlist_head *head;
915 int i, j; 918 uint32_t i;
919 int j;
916 920
917 for (i = 0; i < hash->size; i++) { 921 for (i = 0; i < hash->size; i++) {
918 head = &hash->table[i]; 922 head = &hash->table[i];
@@ -1049,7 +1053,7 @@ static struct sk_buff *tt_response_fill_table(uint16_t tt_len, uint8_t ttvn,
1049 struct sk_buff *skb = NULL; 1053 struct sk_buff *skb = NULL;
1050 uint16_t tt_tot, tt_count; 1054 uint16_t tt_tot, tt_count;
1051 ssize_t tt_query_size = sizeof(struct tt_query_packet); 1055 ssize_t tt_query_size = sizeof(struct tt_query_packet);
1052 int i; 1056 uint32_t i;
1053 1057
1054 if (tt_query_size + tt_len > primary_if->soft_iface->mtu) { 1058 if (tt_query_size + tt_len > primary_if->soft_iface->mtu) {
1055 tt_len = primary_if->soft_iface->mtu - tt_query_size; 1059 tt_len = primary_if->soft_iface->mtu - tt_query_size;
@@ -1726,7 +1730,7 @@ void tt_free(struct bat_priv *bat_priv)
1726 * entry */ 1730 * entry */
1727static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags) 1731static void tt_local_reset_flags(struct bat_priv *bat_priv, uint16_t flags)
1728{ 1732{
1729 int i; 1733 uint32_t i;
1730 struct hashtable_t *hash = bat_priv->tt_local_hash; 1734 struct hashtable_t *hash = bat_priv->tt_local_hash;
1731 struct hlist_head *head; 1735 struct hlist_head *head;
1732 struct hlist_node *node; 1736 struct hlist_node *node;
@@ -1759,7 +1763,7 @@ static void tt_local_purge_pending_clients(struct bat_priv *bat_priv)
1759 struct hlist_node *node, *node_tmp; 1763 struct hlist_node *node, *node_tmp;
1760 struct hlist_head *head; 1764 struct hlist_head *head;
1761 spinlock_t *list_lock; /* protects write access to the hash lists */ 1765 spinlock_t *list_lock; /* protects write access to the hash lists */
1762 int i; 1766 uint32_t i;
1763 1767
1764 if (!hash) 1768 if (!hash)
1765 return; 1769 return;
diff --git a/net/batman-adv/vis.c b/net/batman-adv/vis.c
index f81a6b668b0c..7445413253ca 100644
--- a/net/batman-adv/vis.c
+++ b/net/batman-adv/vis.c
@@ -66,7 +66,7 @@ static int vis_info_cmp(const struct hlist_node *node, const void *data2)
66 66
67/* hash function to choose an entry in a hash table of given size */ 67/* hash function to choose an entry in a hash table of given size */
68/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */ 68/* hash algorithm from http://en.wikipedia.org/wiki/Hash_table */
69static int vis_info_choose(const void *data, int size) 69static uint32_t vis_info_choose(const void *data, uint32_t size)
70{ 70{
71 const struct vis_info *vis_info = data; 71 const struct vis_info *vis_info = data;
72 const struct vis_packet *packet; 72 const struct vis_packet *packet;
@@ -96,7 +96,7 @@ static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
96 struct hlist_head *head; 96 struct hlist_head *head;
97 struct hlist_node *node; 97 struct hlist_node *node;
98 struct vis_info *vis_info, *vis_info_tmp = NULL; 98 struct vis_info *vis_info, *vis_info_tmp = NULL;
99 int index; 99 uint32_t index;
100 100
101 if (!hash) 101 if (!hash)
102 return NULL; 102 return NULL;
@@ -202,7 +202,8 @@ int vis_seq_print_text(struct seq_file *seq, void *offset)
202 HLIST_HEAD(vis_if_list); 202 HLIST_HEAD(vis_if_list);
203 struct if_list_entry *entry; 203 struct if_list_entry *entry;
204 struct hlist_node *pos, *n; 204 struct hlist_node *pos, *n;
205 int i, j, ret = 0; 205 uint32_t i;
206 int j, ret = 0;
206 int vis_server = atomic_read(&bat_priv->vis_mode); 207 int vis_server = atomic_read(&bat_priv->vis_mode);
207 size_t buff_pos, buf_size; 208 size_t buff_pos, buf_size;
208 char *buff; 209 char *buff;
@@ -556,7 +557,8 @@ static int find_best_vis_server(struct bat_priv *bat_priv,
556 struct hlist_head *head; 557 struct hlist_head *head;
557 struct orig_node *orig_node; 558 struct orig_node *orig_node;
558 struct vis_packet *packet; 559 struct vis_packet *packet;
559 int best_tq = -1, i; 560 int best_tq = -1;
561 uint32_t i;
560 562
561 packet = (struct vis_packet *)info->skb_packet->data; 563 packet = (struct vis_packet *)info->skb_packet->data;
562 564
@@ -608,7 +610,8 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
608 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data; 610 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data;
609 struct vis_info_entry *entry; 611 struct vis_info_entry *entry;
610 struct tt_local_entry *tt_local_entry; 612 struct tt_local_entry *tt_local_entry;
611 int best_tq = -1, i; 613 int best_tq = -1;
614 uint32_t i;
612 615
613 info->first_seen = jiffies; 616 info->first_seen = jiffies;
614 packet->vis_type = atomic_read(&bat_priv->vis_mode); 617 packet->vis_type = atomic_read(&bat_priv->vis_mode);
@@ -696,7 +699,7 @@ unlock:
696 * held */ 699 * held */
697static void purge_vis_packets(struct bat_priv *bat_priv) 700static void purge_vis_packets(struct bat_priv *bat_priv)
698{ 701{
699 int i; 702 uint32_t i;
700 struct hashtable_t *hash = bat_priv->vis_hash; 703 struct hashtable_t *hash = bat_priv->vis_hash;
701 struct hlist_node *node, *node_tmp; 704 struct hlist_node *node, *node_tmp;
702 struct hlist_head *head; 705 struct hlist_head *head;
@@ -733,7 +736,7 @@ static void broadcast_vis_packet(struct bat_priv *bat_priv,
733 struct sk_buff *skb; 736 struct sk_buff *skb;
734 struct hard_iface *hard_iface; 737 struct hard_iface *hard_iface;
735 uint8_t dstaddr[ETH_ALEN]; 738 uint8_t dstaddr[ETH_ALEN];
736 int i; 739 uint32_t i;
737 740
738 741
739 packet = (struct vis_packet *)info->skb_packet->data; 742 packet = (struct vis_packet *)info->skb_packet->data;