提交 b4abfcd4 编写于 作者: M Marek Lindner 提交者: Greg Kroah-Hartman

Staging: batman-adv: convert batman_if custom refcounting to kref functions

Signed-off-by: NMarek Lindner <lindner_marek@yahoo.de>
Signed-off-by: NSven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 bd27509f
...@@ -413,7 +413,7 @@ static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr, ...@@ -413,7 +413,7 @@ static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
length = sprintf(buff, "%s\n", batman_if->if_status == IF_NOT_IN_USE ? length = sprintf(buff, "%s\n", batman_if->if_status == IF_NOT_IN_USE ?
"none" : batman_if->soft_iface->name); "none" : batman_if->soft_iface->name);
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return length; return length;
} }
...@@ -436,7 +436,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, ...@@ -436,7 +436,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
if (strlen(buff) >= IFNAMSIZ) { if (strlen(buff) >= IFNAMSIZ) {
pr_err("Invalid parameter for 'mesh_iface' setting received: " pr_err("Invalid parameter for 'mesh_iface' setting received: "
"interface name too long '%s'\n", buff); "interface name too long '%s'\n", buff);
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return -EINVAL; return -EINVAL;
} }
...@@ -447,7 +447,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, ...@@ -447,7 +447,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
if ((batman_if->if_status == status_tmp) || ((batman_if->soft_iface) && if ((batman_if->if_status == status_tmp) || ((batman_if->soft_iface) &&
(strncmp(batman_if->soft_iface->name, buff, IFNAMSIZ) == 0))) { (strncmp(batman_if->soft_iface->name, buff, IFNAMSIZ) == 0))) {
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return count; return count;
} }
...@@ -455,7 +455,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, ...@@ -455,7 +455,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
rtnl_lock(); rtnl_lock();
hardif_disable_interface(batman_if); hardif_disable_interface(batman_if);
rtnl_unlock(); rtnl_unlock();
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return count; return count;
} }
...@@ -467,7 +467,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr, ...@@ -467,7 +467,7 @@ static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
} }
ret = hardif_enable_interface(batman_if, buff); ret = hardif_enable_interface(batman_if, buff);
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return ret; return ret;
} }
...@@ -502,7 +502,7 @@ static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr, ...@@ -502,7 +502,7 @@ static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
break; break;
} }
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
return length; return length;
} }
......
...@@ -50,7 +50,7 @@ struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev) ...@@ -50,7 +50,7 @@ struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
out: out:
if (batman_if) if (batman_if)
hardif_hold(batman_if); kref_get(&batman_if->refcount);
rcu_read_unlock(); rcu_read_unlock();
return batman_if; return batman_if;
...@@ -100,7 +100,7 @@ static struct batman_if *get_active_batman_if(struct net_device *soft_iface) ...@@ -100,7 +100,7 @@ static struct batman_if *get_active_batman_if(struct net_device *soft_iface)
out: out:
if (batman_if) if (batman_if)
hardif_hold(batman_if); kref_get(&batman_if->refcount);
rcu_read_unlock(); rcu_read_unlock();
return batman_if; return batman_if;
...@@ -125,13 +125,13 @@ static void set_primary_if(struct bat_priv *bat_priv, ...@@ -125,13 +125,13 @@ static void set_primary_if(struct bat_priv *bat_priv,
struct batman_if *old_if; struct batman_if *old_if;
if (batman_if) if (batman_if)
hardif_hold(batman_if); kref_get(&batman_if->refcount);
old_if = bat_priv->primary_if; old_if = bat_priv->primary_if;
bat_priv->primary_if = batman_if; bat_priv->primary_if = batman_if;
if (old_if) if (old_if)
hardif_put(old_if); kref_put(&old_if->refcount, hardif_free_ref);
if (!bat_priv->primary_if) if (!bat_priv->primary_if)
return; return;
...@@ -315,7 +315,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name) ...@@ -315,7 +315,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN); batman_if->batman_adv_ptype.type = __constant_htons(ETH_P_BATMAN);
batman_if->batman_adv_ptype.func = batman_skb_recv; batman_if->batman_adv_ptype.func = batman_skb_recv;
batman_if->batman_adv_ptype.dev = batman_if->net_dev; batman_if->batman_adv_ptype.dev = batman_if->net_dev;
hardif_hold(batman_if); kref_get(&batman_if->refcount);
dev_add_pack(&batman_if->batman_adv_ptype); dev_add_pack(&batman_if->batman_adv_ptype);
atomic_set(&batman_if->seqno, 1); atomic_set(&batman_if->seqno, 1);
...@@ -374,7 +374,7 @@ void hardif_disable_interface(struct batman_if *batman_if) ...@@ -374,7 +374,7 @@ void hardif_disable_interface(struct batman_if *batman_if)
bat_info(batman_if->soft_iface, "Removing interface: %s\n", bat_info(batman_if->soft_iface, "Removing interface: %s\n",
batman_if->net_dev->name); batman_if->net_dev->name);
dev_remove_pack(&batman_if->batman_adv_ptype); dev_remove_pack(&batman_if->batman_adv_ptype);
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
bat_priv->num_ifaces--; bat_priv->num_ifaces--;
orig_hash_del_if(batman_if, bat_priv->num_ifaces); orig_hash_del_if(batman_if, bat_priv->num_ifaces);
...@@ -386,7 +386,7 @@ void hardif_disable_interface(struct batman_if *batman_if) ...@@ -386,7 +386,7 @@ void hardif_disable_interface(struct batman_if *batman_if)
set_primary_if(bat_priv, new_if); set_primary_if(bat_priv, new_if);
if (new_if) if (new_if)
hardif_put(new_if); kref_put(&new_if->refcount, hardif_free_ref);
} }
kfree(batman_if->packet_buff); kfree(batman_if->packet_buff);
...@@ -432,8 +432,7 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev) ...@@ -432,8 +432,7 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
batman_if->soft_iface = NULL; batman_if->soft_iface = NULL;
batman_if->if_status = IF_NOT_IN_USE; batman_if->if_status = IF_NOT_IN_USE;
INIT_LIST_HEAD(&batman_if->list); INIT_LIST_HEAD(&batman_if->list);
atomic_set(&batman_if->refcnt, 0); kref_init(&batman_if->refcount);
hardif_hold(batman_if);
check_known_mac_addr(batman_if->net_dev); check_known_mac_addr(batman_if->net_dev);
...@@ -442,7 +441,7 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev) ...@@ -442,7 +441,7 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
spin_unlock(&if_list_lock); spin_unlock(&if_list_lock);
/* extra reference for return */ /* extra reference for return */
hardif_hold(batman_if); kref_get(&batman_if->refcount);
return batman_if; return batman_if;
free_if: free_if:
...@@ -465,7 +464,7 @@ static void hardif_remove_interface(struct batman_if *batman_if) ...@@ -465,7 +464,7 @@ static void hardif_remove_interface(struct batman_if *batman_if)
batman_if->if_status = IF_TO_BE_REMOVED; batman_if->if_status = IF_TO_BE_REMOVED;
synchronize_rcu(); synchronize_rcu();
sysfs_del_hardif(&batman_if->hardif_obj); sysfs_del_hardif(&batman_if->hardif_obj);
hardif_put(batman_if); kref_put(&batman_if->refcount, hardif_free_ref);
} }
void hardif_remove_interfaces(void) void hardif_remove_interfaces(void)
...@@ -522,10 +521,8 @@ static int hard_if_event(struct notifier_block *this, ...@@ -522,10 +521,8 @@ static int hard_if_event(struct notifier_block *this,
update_min_mtu(batman_if->soft_iface); update_min_mtu(batman_if->soft_iface);
break; break;
case NETDEV_CHANGEADDR: case NETDEV_CHANGEADDR:
if (batman_if->if_status == IF_NOT_IN_USE) { if (batman_if->if_status == IF_NOT_IN_USE)
hardif_put(batman_if); goto hardif_put;
goto out;
}
check_known_mac_addr(batman_if->net_dev); check_known_mac_addr(batman_if->net_dev);
update_mac_addresses(batman_if); update_mac_addresses(batman_if);
...@@ -537,8 +534,9 @@ static int hard_if_event(struct notifier_block *this, ...@@ -537,8 +534,9 @@ static int hard_if_event(struct notifier_block *this,
default: default:
break; break;
}; };
hardif_put(batman_if);
hardif_put:
kref_put(&batman_if->refcount, hardif_free_ref);
out: out:
return NOTIFY_DONE; return NOTIFY_DONE;
} }
......
...@@ -42,17 +42,13 @@ int batman_skb_recv(struct sk_buff *skb, ...@@ -42,17 +42,13 @@ int batman_skb_recv(struct sk_buff *skb,
int hardif_min_mtu(struct net_device *soft_iface); int hardif_min_mtu(struct net_device *soft_iface);
void update_min_mtu(struct net_device *soft_iface); void update_min_mtu(struct net_device *soft_iface);
static inline void hardif_hold(struct batman_if *batman_if) static inline void hardif_free_ref(struct kref *refcount)
{ {
atomic_inc(&batman_if->refcnt); struct batman_if *batman_if;
}
static inline void hardif_put(struct batman_if *batman_if) batman_if = container_of(refcount, struct batman_if, refcount);
{ dev_put(batman_if->net_dev);
if (atomic_dec_and_test(&batman_if->refcnt)) { kfree(batman_if);
dev_put(batman_if->net_dev);
kfree(batman_if);
}
} }
#endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */ #endif /* _NET_BATMAN_ADV_HARD_INTERFACE_H_ */
...@@ -43,7 +43,7 @@ struct batman_if { ...@@ -43,7 +43,7 @@ struct batman_if {
unsigned char *packet_buff; unsigned char *packet_buff;
int packet_len; int packet_len;
struct kobject *hardif_obj; struct kobject *hardif_obj;
atomic_t refcnt; struct kref refcount;
struct packet_type batman_adv_ptype; struct packet_type batman_adv_ptype;
struct net_device *soft_iface; struct net_device *soft_iface;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册