Skip to content

Commit f665fa7

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Place kref_get for gw_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 6a51e09 commit f665fa7

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎net/batman-adv/gateway_client.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,15 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
339339
if (!gw_node)
340340
return;
341341

342+
kref_init(&gw_node->refcount);
342343
INIT_HLIST_NODE(&gw_node->list);
343344
kref_get(&orig_node->refcount);
344345
gw_node->orig_node = orig_node;
345346
gw_node->bandwidth_down = ntohl(gateway->bandwidth_down);
346347
gw_node->bandwidth_up = ntohl(gateway->bandwidth_up);
347-
kref_init(&gw_node->refcount);
348348

349349
spin_lock_bh(&bat_priv->gw.list_lock);
350+
kref_get(&gw_node->refcount);
350351
hlist_add_head_rcu(&gw_node->list, &bat_priv->gw.list);
351352
spin_unlock_bh(&bat_priv->gw.list_lock);
352353

@@ -357,6 +358,9 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
357358
ntohl(gateway->bandwidth_down) % 10,
358359
ntohl(gateway->bandwidth_up) / 10,
359360
ntohl(gateway->bandwidth_up) % 10);
361+
362+
/* don't return reference to new gw_node */
363+
batadv_gw_node_put(gw_node);
360364
}
361365

362366
/**

0 commit comments

Comments
 (0)