diff options
-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, | |||
549 | if (tmp_neigh_node->if_incoming == recv_if) | 549 | if (tmp_neigh_node->if_incoming == recv_if) |
550 | continue; | 550 | continue; |
551 | 551 | ||
552 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) | 552 | if (router && tmp_neigh_node->tq_avg <= router->tq_avg) |
553 | continue; | 553 | continue; |
554 | 554 | ||
555 | /* if we don't have a router yet | 555 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) |
556 | * or this one is better, choose it. | 556 | continue; |
557 | */ | ||
558 | if ((!router) || | ||
559 | (tmp_neigh_node->tq_avg > router->tq_avg)) { | ||
560 | /* decrement refcount of | ||
561 | * previously selected router | ||
562 | */ | ||
563 | if (router) | ||
564 | batadv_neigh_node_free_ref(router); | ||
565 | 557 | ||
566 | router = tmp_neigh_node; | 558 | /* decrement refcount of previously selected router */ |
567 | atomic_inc_not_zero(&router->refcount); | 559 | if (router) |
568 | } | 560 | batadv_neigh_node_free_ref(router); |
569 | 561 | ||
570 | batadv_neigh_node_free_ref(tmp_neigh_node); | 562 | /* we found a better router (or at least one valid router) */ |
563 | router = tmp_neigh_node; | ||
571 | } | 564 | } |
572 | 565 | ||
573 | /* use the first candidate if nothing was found. */ | 566 | /* use the first candidate if nothing was found. */ |