Commit 32836f56 authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Antonio Quartulli

batman-adv: Convert batadv_tvlv_handler 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 f7157dd1
...@@ -625,15 +625,27 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr) ...@@ -625,15 +625,27 @@ __be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
} }
/** /**
* batadv_tvlv_handler_free_ref - decrement the tvlv handler refcounter and * batadv_tvlv_handler_release - release tvlv handler from lists and queue for
* possibly free it * free after rcu grace period
* @ref: kref pointer of the tvlv
*/
static void batadv_tvlv_handler_release(struct kref *ref)
{
struct batadv_tvlv_handler *tvlv_handler;
tvlv_handler = container_of(ref, struct batadv_tvlv_handler, refcount);
kfree_rcu(tvlv_handler, rcu);
}
/**
* batadv_tvlv_handler_free_ref - decrement the tvlv container refcounter and
* possibly release it
* @tvlv_handler: the tvlv handler to free * @tvlv_handler: the tvlv handler to free
*/ */
static void static void
batadv_tvlv_handler_free_ref(struct batadv_tvlv_handler *tvlv_handler) batadv_tvlv_handler_free_ref(struct batadv_tvlv_handler *tvlv_handler)
{ {
if (atomic_dec_and_test(&tvlv_handler->refcount)) kref_put(&tvlv_handler->refcount, batadv_tvlv_handler_release);
kfree_rcu(tvlv_handler, rcu);
} }
/** /**
...@@ -659,7 +671,7 @@ static struct batadv_tvlv_handler ...@@ -659,7 +671,7 @@ static struct batadv_tvlv_handler
if (tvlv_handler_tmp->version != version) if (tvlv_handler_tmp->version != version)
continue; continue;
if (!atomic_inc_not_zero(&tvlv_handler_tmp->refcount)) if (!kref_get_unless_zero(&tvlv_handler_tmp->refcount))
continue; continue;
tvlv_handler = tvlv_handler_tmp; tvlv_handler = tvlv_handler_tmp;
...@@ -1112,7 +1124,7 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv, ...@@ -1112,7 +1124,7 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
tvlv_handler->type = type; tvlv_handler->type = type;
tvlv_handler->version = version; tvlv_handler->version = version;
tvlv_handler->flags = flags; tvlv_handler->flags = flags;
atomic_set(&tvlv_handler->refcount, 1); kref_init(&tvlv_handler->refcount);
INIT_HLIST_NODE(&tvlv_handler->list); INIT_HLIST_NODE(&tvlv_handler->list);
spin_lock_bh(&bat_priv->tvlv.handler_list_lock); spin_lock_bh(&bat_priv->tvlv.handler_list_lock);
......
...@@ -1293,7 +1293,7 @@ struct batadv_tvlv_handler { ...@@ -1293,7 +1293,7 @@ struct batadv_tvlv_handler {
u8 type; u8 type;
u8 version; u8 version;
u8 flags; u8 flags;
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