提交 a6ba0d34 编写于 作者: S Sven Eckelmann 提交者: Antonio Quartulli

batman-adv: Convert batadv_orig_ifinfo 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: NSven Eckelmann <sven@narfation.org>
Signed-off-by: NMarek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: NAntonio Quartulli <a@unstable.cc>
上级 962c6832
...@@ -326,7 +326,7 @@ batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node, ...@@ -326,7 +326,7 @@ batadv_orig_ifinfo_get(struct batadv_orig_node *orig_node,
if (tmp->if_outgoing != if_outgoing) if (tmp->if_outgoing != if_outgoing)
continue; continue;
if (!atomic_inc_not_zero(&tmp->refcount)) if (!kref_get_unless_zero(&tmp->refcount))
continue; continue;
orig_ifinfo = tmp; orig_ifinfo = tmp;
...@@ -377,7 +377,8 @@ batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node, ...@@ -377,7 +377,8 @@ batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
orig_ifinfo->batman_seqno_reset = reset_time; orig_ifinfo->batman_seqno_reset = reset_time;
orig_ifinfo->if_outgoing = if_outgoing; orig_ifinfo->if_outgoing = if_outgoing;
INIT_HLIST_NODE(&orig_ifinfo->list); INIT_HLIST_NODE(&orig_ifinfo->list);
atomic_set(&orig_ifinfo->refcount, 2); kref_init(&orig_ifinfo->refcount);
kref_get(&orig_ifinfo->refcount);
hlist_add_head_rcu(&orig_ifinfo->list, hlist_add_head_rcu(&orig_ifinfo->list,
&orig_node->ifinfo_list); &orig_node->ifinfo_list);
out: out:
...@@ -704,12 +705,15 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset) ...@@ -704,12 +705,15 @@ int batadv_hardif_neigh_seq_print_text(struct seq_file *seq, void *offset)
/** /**
* batadv_orig_ifinfo_release - release orig_ifinfo from lists and queue for * batadv_orig_ifinfo_release - release orig_ifinfo from lists and queue for
* free after rcu grace period * free after rcu grace period
* @orig_ifinfo: the orig_ifinfo object to release * @ref: kref pointer of the orig_ifinfo
*/ */
static void batadv_orig_ifinfo_release(struct batadv_orig_ifinfo *orig_ifinfo) static void batadv_orig_ifinfo_release(struct kref *ref)
{ {
struct batadv_orig_ifinfo *orig_ifinfo;
struct batadv_neigh_node *router; struct batadv_neigh_node *router;
orig_ifinfo = container_of(ref, struct batadv_orig_ifinfo, refcount);
if (orig_ifinfo->if_outgoing != BATADV_IF_DEFAULT) if (orig_ifinfo->if_outgoing != BATADV_IF_DEFAULT)
batadv_hardif_free_ref(orig_ifinfo->if_outgoing); batadv_hardif_free_ref(orig_ifinfo->if_outgoing);
...@@ -728,8 +732,7 @@ static void batadv_orig_ifinfo_release(struct batadv_orig_ifinfo *orig_ifinfo) ...@@ -728,8 +732,7 @@ static void batadv_orig_ifinfo_release(struct batadv_orig_ifinfo *orig_ifinfo)
*/ */
void batadv_orig_ifinfo_free_ref(struct batadv_orig_ifinfo *orig_ifinfo) void batadv_orig_ifinfo_free_ref(struct batadv_orig_ifinfo *orig_ifinfo)
{ {
if (atomic_dec_and_test(&orig_ifinfo->refcount)) kref_put(&orig_ifinfo->refcount, batadv_orig_ifinfo_release);
batadv_orig_ifinfo_release(orig_ifinfo);
} }
/** /**
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/kref.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/printk.h> #include <linux/printk.h>
#include <linux/rculist.h> #include <linux/rculist.h>
...@@ -497,7 +498,7 @@ batadv_find_router(struct batadv_priv *bat_priv, ...@@ -497,7 +498,7 @@ batadv_find_router(struct batadv_priv *bat_priv,
hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) { hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) {
/* acquire some structures and references ... */ /* acquire some structures and references ... */
if (!atomic_inc_not_zero(&cand->refcount)) if (!kref_get_unless_zero(&cand->refcount))
continue; continue;
cand_router = rcu_dereference(cand->router); cand_router = rcu_dereference(cand->router);
...@@ -524,7 +525,7 @@ batadv_find_router(struct batadv_priv *bat_priv, ...@@ -524,7 +525,7 @@ batadv_find_router(struct batadv_priv *bat_priv,
/* mark the first possible candidate */ /* mark the first possible candidate */
if (!first_candidate) { if (!first_candidate) {
atomic_inc(&cand_router->refcount); atomic_inc(&cand_router->refcount);
atomic_inc(&cand->refcount); kref_get(&cand->refcount);
first_candidate = cand; first_candidate = cand;
first_candidate_router = cand_router; first_candidate_router = cand_router;
} }
......
...@@ -141,7 +141,7 @@ struct batadv_orig_ifinfo { ...@@ -141,7 +141,7 @@ struct batadv_orig_ifinfo {
u32 last_real_seqno; u32 last_real_seqno;
u8 last_ttl; u8 last_ttl;
unsigned long batman_seqno_reset; unsigned long batman_seqno_reset;
atomic_t refcount; struct kref refcount;
struct rcu_head rcu; struct rcu_head rcu;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册