Skip to content

Commit b2367e4

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Place kref_get for hard_iface near use
It is hard to understand why the refcnt is increased when it isn't done near the actual place the new reference is used. So using kref_get right before the place which requires the reference and in the same function helps to avoid accidental problems caused by incorrect reference counting. Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
1 parent f665fa7 commit b2367e4

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

‎net/batman-adv/hard-interface.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,18 +694,16 @@ batadv_hardif_add_interface(struct net_device *net_dev)
694694
INIT_HLIST_HEAD(&hard_iface->neigh_list);
695695

696696
spin_lock_init(&hard_iface->neigh_list_lock);
697+
kref_init(&hard_iface->refcount);
697698

698699
hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT;
699700
if (batadv_is_wifi_netdev(net_dev))
700701
hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
701702

702703
batadv_v_hardif_init(hard_iface);
703704

704-
/* extra reference for return */
705-
kref_init(&hard_iface->refcount);
706-
kref_get(&hard_iface->refcount);
707-
708705
batadv_check_known_mac_addr(hard_iface->net_dev);
706+
kref_get(&hard_iface->refcount);
709707
list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
710708

711709
return hard_iface;

0 commit comments

Comments
 (0)