]> git.karo-electronics.de Git - linux-beck.git/commitdiff
batman-adv: Place kref_get for gw_node near use
authorSven Eckelmann <sven@narfation.org>
Fri, 15 Jul 2016 15:39:27 +0000 (17:39 +0200)
committerSimon Wunderlich <sw@simonwunderlich.de>
Tue, 9 Aug 2016 05:54:49 +0000 (07:54 +0200)
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>
net/batman-adv/gateway_client.c

index b889e1fdba4d3336e0e00cd37617ff4968e76174..4b51b1cf4f767b209db3abcd2e2309fec9ebdcfe 100644 (file)
@@ -339,14 +339,15 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
        if (!gw_node)
                return;
 
+       kref_init(&gw_node->refcount);
        INIT_HLIST_NODE(&gw_node->list);
        kref_get(&orig_node->refcount);
        gw_node->orig_node = orig_node;
        gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
        gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
-       kref_init(&gw_node->refcount);
 
        spin_lock_bh(&bat_priv->gw.list_lock);
+       kref_get(&gw_node->refcount);
        hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list);
        spin_unlock_bh(&bat_priv->gw.list_lock);
 
@@ -357,6 +358,9 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
                   ntohl(gateway->bandwidth_down) % 10,
                   ntohl(gateway->bandwidth_up) / 10,
                   ntohl(gateway->bandwidth_up) % 10);
+
+       /* don't return reference to new gw_node */
+       batadv_gw_node_put(gw_node);
 }
 
 /**