From patchwork Sat Mar 5 12:28:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 848 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 09985154204 for ; Sat, 5 Mar 2011 13:29:33 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@narfation.org; dkim-adsp=pass Received: from sven-desktop.home.narfation.org (i59F6B254.versanet.de [89.246.178.84]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id AA1C59405E; Sat, 5 Mar 2011 13:29:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1299328175; bh=AYHJNs5y7RRPFE8spJM0zwedL+lvRDZF8M8MNy/2Z+c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=hAVXANlR9HyvdCdtp+PgN89iEnyeQtipPmFIqjGDiyBvSgFczrtrUIBXF0KY5j+Nj wmFyMDw9kmzDWw0sTjdXh2SVftogXYnd9vfBvcEuZ2JePF2/DVqz8zhJeijAC7qkGM bfL6MtF+MMD8NhTwxneglGF6Ba2hZO09224E3XPU= From: Sven Eckelmann To: davem@davemloft.net Date: Sat, 5 Mar 2011 13:28:20 +0100 Message-Id: <1299328122-21468-7-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1299328122-21468-1-git-send-email-sven@narfation.org> References: <1299328122-21468-1-git-send-email-sven@narfation.org> Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 06/28] batman-adv: protect neigh_nodes used outside of rcu_locks with refcounting X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Mar 2011 12:29:33 -0000 From: Marek Lindner Signed-off-by: Marek Lindner --- net/batman-adv/routing.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-) diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 97f3216..c15e6c1 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -151,6 +151,7 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; struct hlist_node *node; unsigned char total_count; + int ret = 0; if (orig_node == orig_neigh_node) { rcu_read_lock(); @@ -162,7 +163,6 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, (tmp_neigh_node->if_incoming == if_incoming)) neigh_node = tmp_neigh_node; } - rcu_read_unlock(); if (!neigh_node) neigh_node = create_neighbor(orig_node, @@ -171,7 +171,10 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, if_incoming); /* create_neighbor failed, return 0 */ if (!neigh_node) - return 0; + goto unlock; + + kref_get(&neigh_node->refcount); + rcu_read_unlock(); neigh_node->last_valid = jiffies; } else { @@ -185,7 +188,6 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, (tmp_neigh_node->if_incoming == if_incoming)) neigh_node = tmp_neigh_node; } - rcu_read_unlock(); if (!neigh_node) neigh_node = create_neighbor(orig_neigh_node, @@ -194,7 +196,10 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, if_incoming); /* create_neighbor failed, return 0 */ if (!neigh_node) - return 0; + goto unlock; + + kref_get(&neigh_node->refcount); + rcu_read_unlock(); } orig_node->last_valid = jiffies; @@ -250,9 +255,16 @@ static int is_bidirectional_neigh(struct orig_node *orig_node, /* if link has the minimum required transmission quality * consider it bidirectional */ if (batman_packet->tq >= TQ_TOTAL_BIDRECT_LIMIT) - return 1; + ret = 1; - return 0; + goto out; + +unlock: + rcu_read_unlock(); +out: + if (neigh_node) + kref_put(&neigh_node->refcount, neigh_node_free_ref); + return ret; } static void update_orig(struct bat_priv *bat_priv, @@ -287,23 +299,25 @@ static void update_orig(struct bat_priv *bat_priv, tmp_neigh_node->tq_avg = ring_buffer_avg(tmp_neigh_node->tq_recv); } - rcu_read_unlock(); if (!neigh_node) { struct orig_node *orig_tmp; orig_tmp = get_orig_node(bat_priv, ethhdr->h_source); if (!orig_tmp) - return; + goto unlock; neigh_node = create_neighbor(orig_node, orig_tmp, ethhdr->h_source, if_incoming); if (!neigh_node) - return; + goto unlock; } else bat_dbg(DBG_BATMAN, bat_priv, "Updating existing last-hop neighbor of originator\n"); + kref_get(&neigh_node->refcount); + rcu_read_unlock(); + orig_node->flags = batman_packet->flags; neigh_node->last_valid = jiffies; @@ -357,6 +371,14 @@ update_gw: (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) && (atomic_read(&bat_priv->gw_sel_class) > 2)) gw_check_election(bat_priv, orig_node); + + goto out; + +unlock: + rcu_read_unlock(); +out: + if (neigh_node) + kref_put(&neigh_node->refcount, neigh_node_free_ref); } /* checks whether the host restarted and is in the protection time.