From patchwork Fri Jul 15 15:39:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16525 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id ED94282CAB; Fri, 15 Jul 2016 17:41:56 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=narfation.org Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=PVCNaCc7; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2001:4d88:2000:7::2; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [IPv6:2001:4d88:2000:7::2]) by open-mesh.org (Postfix) with ESMTPS id 2BFAD82C95 for ; Fri, 15 Jul 2016 17:39:50 +0200 (CEST) Received: from sven-desktop.home.narfation.org (p2003007C6F79CCFEDCC073B09CC56703.dip0.t-ipconnect.de [IPv6:2003:7c:6f79:ccfe:dcc0:73b0:9cc5:6703]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id B85981100F1; Fri, 15 Jul 2016 17:39:49 +0200 (CEST) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1468597189; bh=UKFtqZ9ofwIUFB/3iAvra1j1H9SgBkDVwcjW1Ngip18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVCNaCc7O8+Vh277x+oPqWlIUX1vCjDXlXpMLrh9t69JM2gmifhCfeZTYBa7W3c4z I92WJ63KFFX9Ri5BSJavxkCbp7vy25JIuYSzqpAUr9H++aE5eMcDdn36iwiM6VVHN7 u/rtdt+n/4tmqpmfBYHn2n+vX3AykgJYJqQ3Dk+U= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 15 Jul 2016 17:39:22 +0200 Message-Id: <1468597173-25378-7-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1468597173-25378-1-git-send-email-sven@narfation.org> References: <1468597173-25378-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH v2 07/18] batman-adv: Place kref_get for tt_local_entry near use X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" It is hard to understand why the refcnt is increased when it isn't done near the actual place the new reference is used. So using kref_get right before the place which requires the reference and in the same function helps to avoid accidental problems causedy incorrect reference counting. Signed-off-by: Sven Eckelmann --- v2: - split patch based on type net/batman-adv/translation-table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 89d7b1d..d21b65c 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -727,7 +727,6 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr, if (batadv_is_wifi_netdev(in_dev)) tt_local->common.flags |= BATADV_TT_CLIENT_WIFI; kref_init(&tt_local->common.refcount); - kref_get(&tt_local->common.refcount); tt_local->last_seen = jiffies; tt_local->common.added_at = tt_local->last_seen; tt_local->vlan = vlan; @@ -739,6 +738,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const u8 *addr, is_multicast_ether_addr(addr)) tt_local->common.flags |= BATADV_TT_CLIENT_NOPURGE; + kref_get(&tt_local->common.refcount); hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, batadv_choose_tt, &tt_local->common, &tt_local->common.hash_entry);