Commit 75c5a2e788ab02f67931442e8dcbc854ae7252d1
Committed by
Antonio Quartulli
1 parent
ef3a409391
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>
Showing 1 changed file with 6 additions and 9 deletions Side-by-side Diff
net/batman-adv/hash.h
... | ... | @@ -110,26 +110,23 @@ |
110 | 110 | head = &hash->table[index]; |
111 | 111 | list_lock = &hash->list_locks[index]; |
112 | 112 | |
113 | - rcu_read_lock(); | |
114 | - __hlist_for_each_rcu(node, head) { | |
113 | + spin_lock_bh(list_lock); | |
114 | + | |
115 | + hlist_for_each(node, head) { | |
115 | 116 | if (!compare(node, data)) |
116 | 117 | continue; |
117 | 118 | |
118 | 119 | ret = 1; |
119 | - goto err_unlock; | |
120 | + goto unlock; | |
120 | 121 | } |
121 | - rcu_read_unlock(); | |
122 | 122 | |
123 | 123 | /* no duplicate found in list, add new element */ |
124 | - spin_lock_bh(list_lock); | |
125 | 124 | hlist_add_head_rcu(data_node, head); |
126 | - spin_unlock_bh(list_lock); | |
127 | 125 | |
128 | 126 | ret = 0; |
129 | - goto out; | |
130 | 127 | |
131 | -err_unlock: | |
132 | - rcu_read_unlock(); | |
128 | +unlock: | |
129 | + spin_unlock_bh(list_lock); | |
133 | 130 | out: |
134 | 131 | return ret; |
135 | 132 | } |