|
@@ -18,6 +18,7 @@
|
|
|
#include "hard-interface.h"
|
|
|
#include "main.h"
|
|
|
|
|
|
+#include <linux/atomic.h>
|
|
|
#include <linux/bug.h>
|
|
|
#include <linux/byteorder/generic.h>
|
|
|
#include <linux/errno.h>
|
|
@@ -26,6 +27,7 @@
|
|
|
#include <linux/if_ether.h>
|
|
|
#include <linux/if.h>
|
|
|
#include <linux/kernel.h>
|
|
|
+#include <linux/kref.h>
|
|
|
#include <linux/list.h>
|
|
|
#include <linux/netdevice.h>
|
|
|
#include <linux/printk.h>
|
|
@@ -50,10 +52,13 @@
|
|
|
/**
|
|
|
* batadv_hardif_release - release hard interface from lists and queue for
|
|
|
* free after rcu grace period
|
|
|
- * @hard_iface: the hard interface to free
|
|
|
+ * @ref: kref pointer of the hard interface
|
|
|
*/
|
|
|
-void batadv_hardif_release(struct batadv_hard_iface *hard_iface)
|
|
|
+void batadv_hardif_release(struct kref *ref)
|
|
|
{
|
|
|
+ struct batadv_hard_iface *hard_iface;
|
|
|
+
|
|
|
+ hard_iface = container_of(ref, struct batadv_hard_iface, refcount);
|
|
|
dev_put(hard_iface->net_dev);
|
|
|
|
|
|
kfree_rcu(hard_iface, rcu);
|
|
@@ -67,7 +72,7 @@ batadv_hardif_get_by_netdev(const struct net_device *net_dev)
|
|
|
rcu_read_lock();
|
|
|
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
|
|
|
if (hard_iface->net_dev == net_dev &&
|
|
|
- atomic_inc_not_zero(&hard_iface->refcount))
|
|
|
+ kref_get_unless_zero(&hard_iface->refcount))
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
@@ -172,7 +177,7 @@ batadv_hardif_get_active(const struct net_device *soft_iface)
|
|
|
continue;
|
|
|
|
|
|
if (hard_iface->if_status == BATADV_IF_ACTIVE &&
|
|
|
- atomic_inc_not_zero(&hard_iface->refcount))
|
|
|
+ kref_get_unless_zero(&hard_iface->refcount))
|
|
|
goto out;
|
|
|
}
|
|
|
|
|
@@ -206,7 +211,7 @@ static void batadv_primary_if_select(struct batadv_priv *bat_priv,
|
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
- if (new_hard_iface && !atomic_inc_not_zero(&new_hard_iface->refcount))
|
|
|
+ if (new_hard_iface && !kref_get_unless_zero(&new_hard_iface->refcount))
|
|
|
new_hard_iface = NULL;
|
|
|
|
|
|
curr_hard_iface = rcu_dereference_protected(bat_priv->primary_if, 1);
|
|
@@ -434,7 +439,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
|
|
|
if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
|
|
|
goto out;
|
|
|
|
|
|
- if (!atomic_inc_not_zero(&hard_iface->refcount))
|
|
|
+ if (!kref_get_unless_zero(&hard_iface->refcount))
|
|
|
goto out;
|
|
|
|
|
|
soft_iface = dev_get_by_name(&init_net, iface_name);
|
|
@@ -655,7 +660,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
|
|
|
hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
|
|
|
|
|
|
/* extra reference for return */
|
|
|
- atomic_set(&hard_iface->refcount, 2);
|
|
|
+ kref_init(&hard_iface->refcount);
|
|
|
+ kref_get(&hard_iface->refcount);
|
|
|
|
|
|
batadv_check_known_mac_addr(hard_iface->net_dev);
|
|
|
list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
|