diff options
author | Sven Eckelmann <sven@narfation.org> | 2016-03-05 13:05:24 -0500 |
---|---|---|
committer | Antonio Quartulli <a@unstable.cc> | 2016-05-10 06:28:29 -0400 |
commit | f0b94ebccd2b924237ca7a101da3db70c3a8f0f2 (patch) | |
tree | 106e0a52eaeef4f4816542ed77566916cfe72d93 /net | |
parent | 17a8691502c9d2d792cfea7253b17382279ffb3e (diff) |
batman-adv: Use kref_get for _batadv_update_route
_batadv_update_route requires that the caller already has a valid reference
for neigh_node. It is therefore not possible that it has an reference
counter of 0 and was still given to this function
The kref_get function instead WARNs (with debug information) when the
reference counter would still be 0. This makes a bug in batman-adv better
visible because kref_get_unless_zero would have ignored this problem.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
Diffstat (limited to 'net')
-rw-r--r-- | net/batman-adv/routing.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 2ecfca246be4..b494e435686f 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -100,10 +100,6 @@ static void _batadv_update_route(struct batadv_priv *bat_priv, | |||
100 | if (curr_router) | 100 | if (curr_router) |
101 | batadv_neigh_node_put(curr_router); | 101 | batadv_neigh_node_put(curr_router); |
102 | 102 | ||
103 | /* increase refcount of new best neighbor */ | ||
104 | if (neigh_node && !kref_get_unless_zero(&neigh_node->refcount)) | ||
105 | neigh_node = NULL; | ||
106 | |||
107 | spin_lock_bh(&orig_node->neigh_list_lock); | 103 | spin_lock_bh(&orig_node->neigh_list_lock); |
108 | /* curr_router used earlier may not be the current orig_ifinfo->router | 104 | /* curr_router used earlier may not be the current orig_ifinfo->router |
109 | * anymore because it was dereferenced outside of the neigh_list_lock | 105 | * anymore because it was dereferenced outside of the neigh_list_lock |
@@ -114,6 +110,10 @@ static void _batadv_update_route(struct batadv_priv *bat_priv, | |||
114 | */ | 110 | */ |
115 | curr_router = rcu_dereference_protected(orig_ifinfo->router, true); | 111 | curr_router = rcu_dereference_protected(orig_ifinfo->router, true); |
116 | 112 | ||
113 | /* increase refcount of new best neighbor */ | ||
114 | if (neigh_node) | ||
115 | kref_get(&neigh_node->refcount); | ||
116 | |||
117 | rcu_assign_pointer(orig_ifinfo->router, neigh_node); | 117 | rcu_assign_pointer(orig_ifinfo->router, neigh_node); |
118 | spin_unlock_bh(&orig_node->neigh_list_lock); | 118 | spin_unlock_bh(&orig_node->neigh_list_lock); |
119 | batadv_orig_ifinfo_put(orig_ifinfo); | 119 | batadv_orig_ifinfo_put(orig_ifinfo); |