diff options
author | Sven Eckelmann <sven@narfation.org> | 2016-01-16 04:29:40 -0500 |
---|---|---|
committer | Antonio Quartulli <a@unstable.cc> | 2016-02-10 10:23:58 -0500 |
commit | 90f564dff43c9c62d68568c550c011825f14a899 (patch) | |
tree | 48620c60a32587764d88e21ab0ef6c3bb7f64cfd /net/batman-adv/originator.c | |
parent | dded0692247c76f892adee3ba6878ff5f394e210 (diff) |
batman-adv: Convert batadv_hardif_neigh_node to kref
batman-adv uses a self-written reference implementation which is just based
on atomic_t. This is less obvious when reading the code than kref and
therefore increases the change that the reference counting will be missed.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Diffstat (limited to 'net/batman-adv/originator.c')
-rw-r--r-- | net/batman-adv/originator.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c index d4a30db0158a..7710595ffc42 100644 --- a/net/batman-adv/originator.c +++ b/net/batman-adv/originator.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/fs.h> | 23 | #include <linux/fs.h> |
24 | #include <linux/jiffies.h> | 24 | #include <linux/jiffies.h> |
25 | #include <linux/kernel.h> | 25 | #include <linux/kernel.h> |
26 | #include <linux/kref.h> | ||
26 | #include <linux/list.h> | 27 | #include <linux/list.h> |
27 | #include <linux/lockdep.h> | 28 | #include <linux/lockdep.h> |
28 | #include <linux/netdevice.h> | 29 | #include <linux/netdevice.h> |
@@ -196,11 +197,15 @@ void batadv_neigh_ifinfo_free_ref(struct batadv_neigh_ifinfo *neigh_ifinfo) | |||
196 | /** | 197 | /** |
197 | * batadv_hardif_neigh_release - release hardif neigh node from lists and | 198 | * batadv_hardif_neigh_release - release hardif neigh node from lists and |
198 | * queue for free after rcu grace period | 199 | * queue for free after rcu grace period |
199 | * @hardif_neigh: hardif neigh neighbor to free | 200 | * @ref: kref pointer of the neigh_node |
200 | */ | 201 | */ |
201 | static void | 202 | static void batadv_hardif_neigh_release(struct kref *ref) |
202 | batadv_hardif_neigh_release(struct batadv_hardif_neigh_node *hardif_neigh) | ||
203 | { | 203 | { |
204 | struct batadv_hardif_neigh_node *hardif_neigh; | ||
205 | |||
206 | hardif_neigh = container_of(ref, struct batadv_hardif_neigh_node, | ||
207 | refcount); | ||
208 | |||
204 | spin_lock_bh(&hardif_neigh->if_incoming->neigh_list_lock); | 209 | spin_lock_bh(&hardif_neigh->if_incoming->neigh_list_lock); |
205 | hlist_del_init_rcu(&hardif_neigh->list); | 210 | hlist_del_init_rcu(&hardif_neigh->list); |
206 | spin_unlock_bh(&hardif_neigh->if_incoming->neigh_list_lock); | 211 | spin_unlock_bh(&hardif_neigh->if_incoming->neigh_list_lock); |
@@ -216,8 +221,7 @@ batadv_hardif_neigh_release(struct batadv_hardif_neigh_node *hardif_neigh) | |||
216 | */ | 221 | */ |
217 | void batadv_hardif_neigh_free_ref(struct batadv_hardif_neigh_node *hardif_neigh) | 222 | void batadv_hardif_neigh_free_ref(struct batadv_hardif_neigh_node *hardif_neigh) |
218 | { | 223 | { |
219 | if (atomic_dec_and_test(&hardif_neigh->refcount)) | 224 | kref_put(&hardif_neigh->refcount, batadv_hardif_neigh_release); |
220 | batadv_hardif_neigh_release(hardif_neigh); | ||
221 | } | 225 | } |
222 | 226 | ||
223 | /** | 227 | /** |
@@ -529,7 +533,7 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface, | |||
529 | hardif_neigh->if_incoming = hard_iface; | 533 | hardif_neigh->if_incoming = hard_iface; |
530 | hardif_neigh->last_seen = jiffies; | 534 | hardif_neigh->last_seen = jiffies; |
531 | 535 | ||
532 | atomic_set(&hardif_neigh->refcount, 1); | 536 | kref_init(&hardif_neigh->refcount); |
533 | 537 | ||
534 | if (bat_priv->bat_algo_ops->bat_hardif_neigh_init) | 538 | if (bat_priv->bat_algo_ops->bat_hardif_neigh_init) |
535 | bat_priv->bat_algo_ops->bat_hardif_neigh_init(hardif_neigh); | 539 | bat_priv->bat_algo_ops->bat_hardif_neigh_init(hardif_neigh); |
@@ -584,7 +588,7 @@ batadv_hardif_neigh_get(const struct batadv_hard_iface *hard_iface, | |||
584 | if (!batadv_compare_eth(tmp_hardif_neigh->addr, neigh_addr)) | 588 | if (!batadv_compare_eth(tmp_hardif_neigh->addr, neigh_addr)) |
585 | continue; | 589 | continue; |
586 | 590 | ||
587 | if (!atomic_inc_not_zero(&tmp_hardif_neigh->refcount)) | 591 | if (!kref_get_unless_zero(&tmp_hardif_neigh->refcount)) |
588 | continue; | 592 | continue; |
589 | 593 | ||
590 | hardif_neigh = tmp_hardif_neigh; | 594 | hardif_neigh = tmp_hardif_neigh; |
@@ -648,7 +652,7 @@ batadv_neigh_node_new(struct batadv_orig_node *orig_node, | |||
648 | spin_unlock_bh(&orig_node->neigh_list_lock); | 652 | spin_unlock_bh(&orig_node->neigh_list_lock); |
649 | 653 | ||
650 | /* increment unique neighbor refcount */ | 654 | /* increment unique neighbor refcount */ |
651 | atomic_inc(&hardif_neigh->refcount); | 655 | kref_get(&hardif_neigh->refcount); |
652 | 656 | ||
653 | batadv_dbg(BATADV_DBG_BATMAN, orig_node->bat_priv, | 657 | batadv_dbg(BATADV_DBG_BATMAN, orig_node->bat_priv, |
654 | "Creating new neighbor %pM for orig_node %pM on interface %s\n", | 658 | "Creating new neighbor %pM for orig_node %pM on interface %s\n", |