Skip to content

Commit da7a26a

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Place kref_get for nc_node 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 df28ca6 commit da7a26a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎net/batman-adv/network-coding.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,6 @@ batadv_nc_get_nc_node(struct batadv_priv *bat_priv,
859859
/* Initialize nc_node */
860860
INIT_LIST_HEAD(&nc_node->list);
861861
kref_init(&nc_node->refcount);
862-
kref_get(&nc_node->refcount);
863862
ether_addr_copy(nc_node->addr, orig_node->orig);
864863
kref_get(&orig_neigh_node->refcount);
865864
nc_node->orig_node = orig_neigh_node;
@@ -878,6 +877,7 @@ batadv_nc_get_nc_node(struct batadv_priv *bat_priv,
878877

879878
/* Add nc_node to orig_node */
880879
spin_lock_bh(lock);
880+
kref_get(&nc_node->refcount);
881881
list_add_tail_rcu(&nc_node->list, list);
882882
spin_unlock_bh(lock);
883883

0 commit comments

Comments
 (0)