Commit 75c5a2e7 authored by Matthias Schiffer's avatar Matthias Schiffer Committed by Antonio Quartulli

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: default avatarMatthias Schiffer <mschiffer@universe-factory.net>
Acked-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
parent ef3a4093
...@@ -110,26 +110,23 @@ static inline int hash_add(struct hashtable_t *hash, ...@@ -110,26 +110,23 @@ static inline int hash_add(struct hashtable_t *hash,
head = &hash->table[index]; head = &hash->table[index];
list_lock = &hash->list_locks[index]; list_lock = &hash->list_locks[index];
rcu_read_lock(); spin_lock_bh(list_lock);
__hlist_for_each_rcu(node, head) {
hlist_for_each(node, head) {
if (!compare(node, data)) if (!compare(node, data))
continue; continue;
ret = 1; ret = 1;
goto err_unlock; goto unlock;
} }
rcu_read_unlock();
/* no duplicate found in list, add new element */ /* no duplicate found in list, add new element */
spin_lock_bh(list_lock);
hlist_add_head_rcu(data_node, head); hlist_add_head_rcu(data_node, head);
spin_unlock_bh(list_lock);
ret = 0; ret = 0;
goto out;
err_unlock: unlock:
rcu_read_unlock(); spin_unlock_bh(list_lock);
out: out:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment