From patchwork Sun Oct 28 11:17:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 194681 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5A8792C0086 for ; Sun, 28 Oct 2012 22:18:36 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752163Ab2J1LSe (ORCPT ); Sun, 28 Oct 2012 07:18:34 -0400 Received: from latitanza.investici.org ([82.94.249.234]:55967 "EHLO latitanza.investici.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752097Ab2J1LSd (ORCPT ); Sun, 28 Oct 2012 07:18:33 -0400 Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 57FF99816D; Sun, 28 Oct 2012 11:18:30 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org 57FF99816D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1351423112; bh=0Cj5vdqKcPi4OECZ0c0mCckLhKIFMoGKOCN4Dq/pFoo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=AB+Z09D2pfu/oPeh43coDG904ZmBSSnlK/pKDLzdlP7SoGyhjMibAFO9tDCig7Ca6 8V9VVwLVeoftIUNw2SRMLEbPslGNDkcrXX8jCwKzXlK8K77+jjRa9ZvXiHA5X+FhWX mD6BAJ+6LScJF6Q/CJtuPI5xX7pWNszWiJvVS3jM= From: Antonio Quartulli To: davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann , Antonio Quartulli Subject: [PATCH 09/16] batman-adv: Only increase refcounter once for alternate router Date: Sun, 28 Oct 2012 12:17:10 +0100 Message-Id: <1351423037-5292-10-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1351423037-5292-1-git-send-email-ordex@autistici.org> References: <1351423037-5292-1-git-send-email-ordex@autistici.org> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Sven Eckelmann 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 Signed-off-by: Antonio Quartulli --- net/batman-adv/routing.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 8bdafc8..1ac072d 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 (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. */