batman-adv: Add reference counting + nullptr fixes
[feed/routing.git] / batman-adv / patches / 0004-batman-adv-Fix-orig_node_vlan-leak-on-orig_node_rele.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Thu, 30 Jun 2016 20:10:46 +0200
3 Subject: [PATCH] batman-adv: Fix orig_node_vlan leak on orig_node_release
4
5 batadv_orig_node_new uses batadv_orig_node_vlan_new to allocate a new
6 batadv_orig_node_vlan and add it to batadv_orig_node::vlan_list. References
7 to this list have also to be cleaned when the batadv_orig_node is removed.
8
9 Fixes: 21a57f6e7a3b ("batman-adv: make the TT CRC logic VLAN specific")
10 Signed-off-by: Sven Eckelmann <sven@narfation.org>
11 Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
12
13 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/719afd254e812c7ff8688ce79bebb7324ec438d6
14 ---
15 net/batman-adv/originator.c | 8 ++++++++
16 1 file changed, 8 insertions(+)
17
18 diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
19 index 7f51bc2..fe2fcda 100644
20 --- a/net/batman-adv/originator.c
21 +++ b/net/batman-adv/originator.c
22 @@ -765,6 +765,7 @@ static void batadv_orig_node_release(struct kref *ref)
23 struct batadv_neigh_node *neigh_node;
24 struct batadv_orig_node *orig_node;
25 struct batadv_orig_ifinfo *orig_ifinfo;
26 + struct batadv_orig_node_vlan *vlan;
27
28 orig_node = container_of(ref, struct batadv_orig_node, refcount);
29
30 @@ -784,6 +785,13 @@ static void batadv_orig_node_release(struct kref *ref)
31 }
32 spin_unlock_bh(&orig_node->neigh_list_lock);
33
34 + spin_lock_bh(&orig_node->vlan_list_lock);
35 + hlist_for_each_entry_safe(vlan, node_tmp, &orig_node->vlan_list, list) {
36 + hlist_del_rcu(&vlan->list);
37 + batadv_orig_node_vlan_put(vlan);
38 + }
39 + spin_unlock_bh(&orig_node->vlan_list_lock);
40 +
41 /* Free nc_nodes */
42 batadv_nc_purge_orig(orig_node->bat_priv, orig_node, NULL);
43