public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Only increase refcounter once for alternate router
Date: Mon, 20 Aug 2012 10:26:49 +0200	[thread overview]
Message-ID: <1345451209-8898-3-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1345451209-8898-1-git-send-email-sven@narfation.org>

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>
---
 routing.c |   23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/routing.c b/routing.c
index 939fc01..cdd81d8 100644
--- a/routing.c
+++ b/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 (router && tmp_neigh_node->tq_avg <= router->tq_avg)
+			continue;
+
 		if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
 			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);
+		/* decrement refcount of previously selected router */
+		if (router)
+			batadv_neigh_node_free_ref(router);
 
-			router = tmp_neigh_node;
-			atomic_inc_not_zero(&router->refcount);
-		}
-
-		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. */
-- 
1.7.10.4


  parent reply	other threads:[~2012-08-20  8:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20  8:26 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove extra check in batadv_bit_get_packet Sven Eckelmann
2012-08-20  8:26 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: Check return value of try_module_get Sven Eckelmann
2012-08-20 21:37   ` [B.A.T.M.A.N.] [PATCHv3 " Sven Eckelmann
2012-08-24 22:08     ` Marek Lindner
2012-08-20  8:26 ` Sven Eckelmann [this message]
2012-08-24 22:19   ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: Only increase refcounter once for alternate router Marek Lindner
2012-08-20 20:54 ` [B.A.T.M.A.N.] [PATCHv2 2/3] batman-adv: Check return value of try_module_get Sven Eckelmann
2012-08-24 21:59 ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: Remove extra check in batadv_bit_get_packet Marek Lindner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345451209-8898-3-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox