diff options
author | Sven Eckelmann <sven@narfation.org> | 2012-08-20 12:26:49 +0400 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2012-10-29 12:42:38 +0400 |
commit | fe3f4cfe8ef8b4f0979a0dd61f60de832848664a (patch) | |
tree | 2b1ccaecbee36f0a323fa65d6a40e969516a5822 /net/batman-adv | |
parent | bd5b80d51a6c4a68f7d4b9b92c495329f47e53d4 (diff) | |
download | linux-fe3f4cfe8ef8b4f0979a0dd61f60de832848664a.tar.xz |
batman-adv: Only increase refcounter once for alternate router
The test whether we can use a router for alternating bonding should only be
done once because it is already known that it is still usable and will not be
deleted from the list soon.
This patch addresses Coverity #712285: Unchecked return value
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/routing.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 8bdafc85ba4f..1ac072d7409e 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -549,25 +549,18 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, if (tmp_neigh_node->if_incoming == recv_if) continue; - if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) + if (router && tmp_neigh_node->tq_avg <= router->tq_avg) continue; - /* if we don't have a router yet - * or this one is better, choose it. - */ - if ((!router) || - (tmp_neigh_node->tq_avg > router->tq_avg)) { - /* decrement refcount of - * previously selected router - */ - if (router) - batadv_neigh_node_free_ref(router); + if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) + continue; - router = tmp_neigh_node; - atomic_inc_not_zero(&router->refcount); - } + /* decrement refcount of previously selected router */ + if (router) + batadv_neigh_node_free_ref(router); - batadv_neigh_node_free_ref(tmp_neigh_node); + /* we found a better router (or at least one valid router) */ + router = tmp_neigh_node; } /* use the first candidate if nothing was found. */ |