public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Simon Wunderlich <sw@simonwunderlich.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Simon Wunderlich <simon@open-mesh.com>
Subject: [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: fix rcu pointer comparison problem
Date: Sun, 24 Nov 2013 14:05:45 +0100	[thread overview]
Message-ID: <1385298345-13746-3-git-send-email-sw@simonwunderlich.de> (raw)
In-Reply-To: <1385298345-13746-1-git-send-email-sw@simonwunderlich.de>

From: Simon Wunderlich <simon@open-mesh.com>

sparse complained about:

routing.c:482:64: error: incompatible types in comparison expression
(different address spaces)

This was due to comparing a __rcu pointer with a regular one. Fix that
by adding the missing rcu_dereference call. A temporary variable is used
to comply with the line length limit, use the opportunity to beautify a
few other places.

This problem was introduced in commit
797edd9e87ac838711e03498a4ae795b600191af ("batman-adv: add bonding
again")

Signed-off-by: Simon Wunderlich <simon@open-mesh.com>
---
 routing.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/routing.c b/routing.c
index 23311f5..7aac5b3 100644
--- a/routing.c
+++ b/routing.c
@@ -430,8 +430,10 @@ batadv_find_router(struct batadv_priv *bat_priv,
 	struct batadv_neigh_node *first_candidate_router = NULL;
 	struct batadv_neigh_node *next_candidate_router = NULL;
 	struct batadv_neigh_node *router, *cand_router = NULL;
+	struct batadv_neigh_node *last_cand_router = NULL;
 	struct batadv_orig_ifinfo *cand, *first_candidate = NULL;
 	struct batadv_orig_ifinfo *next_candidate = NULL;
+	struct batadv_orig_ifinfo *last_candidate;
 	bool last_candidate_found = false;
 
 	if (!orig_node)
@@ -455,6 +457,10 @@ batadv_find_router(struct batadv_priv *bat_priv,
 	 * router - obviously there are no other candidates.
 	 */
 	rcu_read_lock();
+	last_candidate = orig_node->last_bonding_candidate;
+	if (last_candidate)
+		last_cand_router = rcu_dereference(last_candidate->router);
+
 	hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) {
 		/* acquire some structures and references ... */
 		if (!atomic_inc_not_zero(&cand->refcount))
@@ -478,9 +484,8 @@ batadv_find_router(struct batadv_priv *bat_priv,
 			goto next;
 
 		/* don't use the same router twice */
-		if (orig_node->last_bonding_candidate &&
-		    (orig_node->last_bonding_candidate->router == cand_router))
-				goto next;
+		if (last_cand_router == cand_router)
+			goto next;
 
 		/* mark the first possible candidate */
 		if (!first_candidate) {
@@ -494,14 +499,13 @@ batadv_find_router(struct batadv_priv *bat_priv,
 		 * candidate ... this function should select the next candidate
 		 * AFTER the previously used bonding candidate.
 		 */
-		if (!orig_node->last_bonding_candidate ||
-		    last_candidate_found) {
+		if (!last_candidate || last_candidate_found) {
 			next_candidate = cand;
 			next_candidate_router = cand_router;
 			break;
 		}
 
-		if (orig_node->last_bonding_candidate == cand)
+		if (last_candidate == cand)
 			last_candidate_found = true;
 next:
 		/* free references */
-- 
1.7.10.4


  parent reply	other threads:[~2013-11-24 13:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-24 13:05 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: fix another sparse warning in batadv_iv_ogm_emit Simon Wunderlich
2013-11-24 13:05 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: fix wrong alignment for batadv_originators_hardif_open Simon Wunderlich
2013-11-25 17:49   ` Marek Lindner
2013-11-24 13:05 ` Simon Wunderlich [this message]
2013-11-25 17:51   ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: fix rcu pointer comparison problem Marek Lindner
2013-11-25 17:48 ` [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: fix another sparse warning in batadv_iv_ogm_emit 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=1385298345-13746-3-git-send-email-sw@simonwunderlich.de \
    --to=sw@simonwunderlich.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=simon@open-mesh.com \
    /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