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

batman-adv: Convert batadv_softif_vlan 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>
上级 e7aed321
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/if_vlan.h> #include <linux/if_vlan.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>
...@@ -477,9 +478,27 @@ void batadv_interface_rx(struct net_device *soft_iface, ...@@ -477,9 +478,27 @@ void batadv_interface_rx(struct net_device *soft_iface,
return; return;
} }
/**
* batadv_softif_vlan_release - release vlan from lists and queue for free after
* rcu grace period
* @ref: kref pointer of the vlan object
*/
static void batadv_softif_vlan_release(struct kref *ref)
{
struct batadv_softif_vlan *vlan;
vlan = container_of(ref, struct batadv_softif_vlan, refcount);
spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
hlist_del_rcu(&vlan->list);
spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
kfree_rcu(vlan, rcu);
}
/** /**
* batadv_softif_vlan_free_ref - decrease the vlan object refcounter and * batadv_softif_vlan_free_ref - decrease the vlan object refcounter and
* possibly free it * possibly release it
* @vlan: the vlan object to release * @vlan: the vlan object to release
*/ */
void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan) void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
...@@ -487,13 +506,7 @@ void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan) ...@@ -487,13 +506,7 @@ void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
if (!vlan) if (!vlan)
return; return;
if (atomic_dec_and_test(&vlan->refcount)) { kref_put(&vlan->refcount, batadv_softif_vlan_release);
spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
hlist_del_rcu(&vlan->list);
spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
kfree_rcu(vlan, rcu);
}
} }
/** /**
...@@ -514,7 +527,7 @@ struct batadv_softif_vlan *batadv_softif_vlan_get(struct batadv_priv *bat_priv, ...@@ -514,7 +527,7 @@ struct batadv_softif_vlan *batadv_softif_vlan_get(struct batadv_priv *bat_priv,
if (vlan_tmp->vid != vid) if (vlan_tmp->vid != vid)
continue; continue;
if (!atomic_inc_not_zero(&vlan_tmp->refcount)) if (!kref_get_unless_zero(&vlan_tmp->refcount))
continue; continue;
vlan = vlan_tmp; vlan = vlan_tmp;
...@@ -549,7 +562,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid) ...@@ -549,7 +562,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
vlan->bat_priv = bat_priv; vlan->bat_priv = bat_priv;
vlan->vid = vid; vlan->vid = vid;
atomic_set(&vlan->refcount, 1); kref_init(&vlan->refcount);
atomic_set(&vlan->ap_isolation, 0); atomic_set(&vlan->ap_isolation, 0);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/if.h> #include <linux/if.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/kref.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/printk.h> #include <linux/printk.h>
...@@ -97,7 +98,7 @@ batadv_kobj_to_vlan(struct batadv_priv *bat_priv, struct kobject *obj) ...@@ -97,7 +98,7 @@ batadv_kobj_to_vlan(struct batadv_priv *bat_priv, struct kobject *obj)
if (vlan_tmp->kobj != obj) if (vlan_tmp->kobj != obj)
continue; continue;
if (!atomic_inc_not_zero(&vlan_tmp->refcount)) if (!kref_get_unless_zero(&vlan_tmp->refcount))
continue; continue;
vlan = vlan_tmp; vlan = vlan_tmp;
......
...@@ -746,7 +746,7 @@ struct batadv_softif_vlan { ...@@ -746,7 +746,7 @@ struct batadv_softif_vlan {
atomic_t ap_isolation; /* boolean */ atomic_t ap_isolation; /* boolean */
struct batadv_vlan_tt tt; struct batadv_vlan_tt tt;
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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册