Commit 6e8ef69d authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Antonio Quartulli

batman-adv: Convert batadv_tt_orig_list_entry 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: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarMarek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: default avatarAntonio Quartulli <a@unstable.cc>
parent 32836f56
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/jhash.h> #include <linux/jhash.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/kref.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
...@@ -346,22 +347,28 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node, ...@@ -346,22 +347,28 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
/** /**
* batadv_tt_orig_list_entry_release - release tt orig entry from lists and * batadv_tt_orig_list_entry_release - release tt orig entry from lists and
* queue for free after rcu grace period * queue for free after rcu grace period
* @orig_entry: tt orig entry to be free'd * @ref: kref pointer of the tt orig entry
*/ */
static void static void batadv_tt_orig_list_entry_release(struct kref *ref)
batadv_tt_orig_list_entry_release(struct batadv_tt_orig_list_entry *orig_entry)
{ {
struct batadv_tt_orig_list_entry *orig_entry;
orig_entry = container_of(ref, struct batadv_tt_orig_list_entry,
refcount);
batadv_orig_node_free_ref(orig_entry->orig_node); batadv_orig_node_free_ref(orig_entry->orig_node);
kfree_rcu(orig_entry, rcu); kfree_rcu(orig_entry, rcu);
} }
/**
* batadv_tt_orig_list_entry_free_ref - decrement the tt orig entry refcounter
* and possibly release it
* @orig_entry: tt orig entry to be free'd
*/
static void static void
batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry) batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry)
{ {
if (!atomic_dec_and_test(&orig_entry->refcount)) kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
return;
batadv_tt_orig_list_entry_release(orig_entry);
} }
/** /**
...@@ -1270,7 +1277,7 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry, ...@@ -1270,7 +1277,7 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
hlist_for_each_entry_rcu(tmp_orig_entry, head, list) { hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
if (tmp_orig_entry->orig_node != orig_node) if (tmp_orig_entry->orig_node != orig_node)
continue; continue;
if (!atomic_inc_not_zero(&tmp_orig_entry->refcount)) if (!kref_get_unless_zero(&tmp_orig_entry->refcount))
continue; continue;
orig_entry = tmp_orig_entry; orig_entry = tmp_orig_entry;
...@@ -1331,7 +1338,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global, ...@@ -1331,7 +1338,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
batadv_tt_global_size_inc(orig_node, tt_global->common.vid); batadv_tt_global_size_inc(orig_node, tt_global->common.vid);
orig_entry->orig_node = orig_node; orig_entry->orig_node = orig_node;
orig_entry->ttvn = ttvn; orig_entry->ttvn = ttvn;
atomic_set(&orig_entry->refcount, 2); kref_init(&orig_entry->refcount);
kref_get(&orig_entry->refcount);
spin_lock_bh(&tt_global->list_lock); spin_lock_bh(&tt_global->list_lock);
hlist_add_head_rcu(&orig_entry->list, hlist_add_head_rcu(&orig_entry->list,
......
...@@ -1014,7 +1014,7 @@ struct batadv_tt_orig_list_entry { ...@@ -1014,7 +1014,7 @@ struct batadv_tt_orig_list_entry {
struct batadv_orig_node *orig_node; struct batadv_orig_node *orig_node;
u8 ttvn; u8 ttvn;
struct hlist_node list; struct hlist_node list;
atomic_t refcount; struct kref refcount;
struct rcu_head rcu; struct rcu_head rcu;
}; };
......
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