From patchwork Fri Jul 15 15:39:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16524 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 89C8382C95; Fri, 15 Jul 2016 17:41:48 +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=IyTdAeGM; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; 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 [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id BE6B682C95 for ; Fri, 15 Jul 2016 17:39:54 +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 5810B11010B; Fri, 15 Jul 2016 17:39:54 +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=1468597194; bh=Ra3ydK92wUD5BuihrjkLoi3skdf75HKgY0AxnKciUiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IyTdAeGMCE2yN2dCCudvP/51glgl1raW9oNWSLjPyKgPXgFyq4jxrj9Vtbgg3EbbF 7jS1iKQjzx3h7MyLFLMRz08PK2YaDCnzp1LoAQukuXvqPZD3qmA8HqfrPf5p8mts4N ZT7M1At3JlYwv/vrI5hzVZr2dmV1ZxGQLgAvB6Yg= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 15 Jul 2016 17:39:28 +0200 Message-Id: <1468597173-25378-13-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 13/18] batman-adv: Place kref_get for hard_iface 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/hard-interface.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 714af8e..adb0377 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -658,6 +658,7 @@ batadv_hardif_add_interface(struct net_device *net_dev) INIT_HLIST_HEAD(&hard_iface->neigh_list); spin_lock_init(&hard_iface->neigh_list_lock); + kref_init(&hard_iface->refcount); hard_iface->num_bcasts = BATADV_NUM_BCASTS_DEFAULT; if (batadv_is_wifi_netdev(net_dev)) @@ -665,11 +666,8 @@ batadv_hardif_add_interface(struct net_device *net_dev) batadv_v_hardif_init(hard_iface); - /* extra reference for return */ - kref_init(&hard_iface->refcount); - kref_get(&hard_iface->refcount); - batadv_check_known_mac_addr(hard_iface->net_dev); + kref_get(&hard_iface->refcount); list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list); return hard_iface;