Skip to content

Commit df28ca6

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

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
594594
}
595595

596596
spin_lock_bh(&bat_priv->softif_vlan_list_lock);
597+
kref_get(&vlan->refcount);
597598
hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
598599
spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
599600

@@ -604,6 +605,9 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
604605
bat_priv->soft_iface->dev_addr, vid,
605606
BATADV_NULL_IFINDEX, BATADV_NO_MARK);
606607

608+
/* don't return reference to new softif_vlan */
609+
batadv_softif_vlan_put(vlan);
610+
607611
return 0;
608612
}
609613

0 commit comments

Comments
 (0)