aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-05-08 16:31:57 -0400
committerAntonio Quartulli <ordex@autistici.org>2012-06-18 12:01:06 -0400
commit75c5a2e788ab02f67931442e8dcbc854ae7252d1 (patch)
treef1ae84324fe9990fa8b04edd17384e644d8cb73b
parentef3a409391f55ad0bddbf017d4d4987b783a3059 (diff)
batman-adv: fix locking in hash_add()
To ensure an entry isn't added twice all comparisons have to be protected by the hash line write spinlock. This doesn't really hurt as the case that it is tried to add an element already present to the hash shouldn't occur very often, so in most cases the lock would have have to be taken anyways. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net> Acked-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Sven Eckelmann <sven@narfation.org>
-rw-r--r--net/batman-adv/hash.h15
1 files changed, 6 insertions, 9 deletions
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index 93b3c71aeaf8..3d67ce49fc31 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -110,26 +110,23 @@ static inline int hash_add(struct hashtable_t *hash,
110 head = &hash->table[index]; 110 head = &hash->table[index];
111 list_lock = &hash->list_locks[index]; 111 list_lock = &hash->list_locks[index];
112 112
113 rcu_read_lock(); 113 spin_lock_bh(list_lock);
114 __hlist_for_each_rcu(node, head) { 114
115 hlist_for_each(node, head) {
115 if (!compare(node, data)) 116 if (!compare(node, data))
116 continue; 117 continue;
117 118
118 ret = 1; 119 ret = 1;
119 goto err_unlock; 120 goto unlock;
120 } 121 }
121 rcu_read_unlock();
122 122
123 /* no duplicate found in list, add new element */ 123 /* no duplicate found in list, add new element */
124 spin_lock_bh(list_lock);
125 hlist_add_head_rcu(data_node, head); 124 hlist_add_head_rcu(data_node, head);
126 spin_unlock_bh(list_lock);
127 125
128 ret = 0; 126 ret = 0;
129 goto out;
130 127
131err_unlock: 128unlock:
132 rcu_read_unlock(); 129 spin_unlock_bh(list_lock);
133out: 130out:
134 return ret; 131 return ret;
135} 132}