Received: by 10.223.164.221 with SMTP id h29csp354631wrb; Fri, 3 Nov 2017 16:06:52 -0700 (PDT) X-Google-Smtp-Source: ABhQp+REJa9b7EjP45A8ucyYBFGKkHBRAMeaAVF5qeW1ZTXz03HFeGlgfkAevARE107Ntj8jFfxw X-Received: by 10.98.131.197 with SMTP id h188mr9214861pfe.224.1509750412654; Fri, 03 Nov 2017 16:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509750412; cv=none; d=google.com; s=arc-20160816; b=eAlyWXmNsWkKPYmPNhlJxWZ7CNbYXIH4tq7lpEjo1xz6sHqTS4J8LYZdWjjYjlIwBI gMdb4TI04hZoNa0/SPjuBpymK7FCcjdrtqIRS+Rt/LB+gogw+BcwYghIa6TB2QMf0UBP sI7J6k2IT5SmxGvBwb19Qn0vmGI8nWFfzHynb/CCgNz94KZsKu5BSmYZ1P7Ep2Hj0hlo SRJk0dpOmvoDIv/mqx4TpPn34bgBQ9OfIbkPB2vrRXskAwZVMyjk1bFdsoE+E5eM8L/a l7WDrM1r7CKraSRwbeH2RzWSTZX86HNRAKBwsmfELyIsdnwvaPWhZXV6cm+QsBKz/4GG 25Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=zsxSX05odcEAUYAsGhNMTSLEaBCOKw154gKzk5Oeq+8=; b=E3GNqYR8QlHDDlkgrv/A8Jc4g2WnKndW75XlQwfuSDKLr06ecTki7s8EOQwwzlSgD8 dzurohOqZ2K0TyUUl/c2tIVzRRcI+++c1ZKPkh7VcqAKEnwFTqIC4NZ1K4mXZMs/OlCs aNFUS8MEwVXc62dXjcRoiE/EuptlGEgtvGFnAinE/ldkvHQP/gkMWbWxFOU4Z7N/a9MM PbmuEmBLe7NyIMhSqYfZBH3t2KMLv553O63vyksxhsC28T6a4OOXbollq5hXxXdFt3ko TOXuk0LyqE5nUS4qVchfLfQhHEOTdU14MfBOdebQ4XP6m5wUtWzSygvCFEKAAZQHrdmr 4bRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12si7404135pfd.342.2017.11.03.16.06.40; Fri, 03 Nov 2017 16:06:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933255AbdKCXGF (ORCPT + 92 others); Fri, 3 Nov 2017 19:06:05 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:33250 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752329AbdKCXF4 (ORCPT ); Fri, 3 Nov 2017 19:05:56 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id AD8709C2F12; Fri, 3 Nov 2017 19:05:54 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 5YwTG9058-eA; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id D33299C3022; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ZbYhN7dd6C-i; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) Received: from weeman.mtl.sfl (unknown [192.168.49.192]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 9ABB79C2F4E; Fri, 3 Nov 2017 19:05:46 -0400 (EDT) From: Vivien Didelot To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com, "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot Subject: [PATCH net-next 04/11] net: dsa: get and put tree reference counting Date: Fri, 3 Nov 2017 19:05:23 -0400 Message-Id: <20171103230530.996-5-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103230530.996-1-vivien.didelot@savoirfairelinux.com> References: <20171103230530.996-1-vivien.didelot@savoirfairelinux.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide convenient dsa_tree_get and dsa_tree_put functions scoping a DSA tree used to increment and decrement its reference counter, instead of poking directly its kref structure. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index d3f1a7607463..609d92684505 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -38,15 +38,6 @@ static struct dsa_switch_tree *dsa_get_dst(unsigned int index) return NULL; } -static void dsa_free_dst(struct kref *ref) -{ - struct dsa_switch_tree *dst = container_of(ref, struct dsa_switch_tree, - refcount); - - list_del(&dst->list); - kfree(dst); -} - static struct dsa_switch_tree *dsa_add_dst(unsigned int index) { struct dsa_switch_tree *dst; @@ -65,10 +56,35 @@ static struct dsa_switch_tree *dsa_add_dst(unsigned int index) return dst; } -static void dsa_dst_add_ds(struct dsa_switch_tree *dst, - struct dsa_switch *ds, u32 index) +static void dsa_tree_free(struct dsa_switch_tree *dst) +{ + list_del(&dst->list); + kfree(dst); +} + +static void dsa_tree_get(struct dsa_switch_tree *dst) { kref_get(&dst->refcount); +} + +static void dsa_tree_release(struct kref *ref) +{ + struct dsa_switch_tree *dst; + + dst = container_of(ref, struct dsa_switch_tree, refcount); + + dsa_tree_free(dst); +} + +static void dsa_tree_put(struct dsa_switch_tree *dst) +{ + kref_put(&dst->refcount, dsa_tree_release); +} + +static void dsa_dst_add_ds(struct dsa_switch_tree *dst, + struct dsa_switch *ds, u32 index) +{ + dsa_tree_get(dst); dst->ds[index] = ds; } @@ -76,7 +92,7 @@ static void dsa_dst_del_ds(struct dsa_switch_tree *dst, struct dsa_switch *ds, u32 index) { dst->ds[index] = NULL; - kref_put(&dst->refcount, dsa_free_dst); + dsa_tree_put(dst); } /* For platform data configurations, we need to have a valid name argument to -- 2.14.3 From 1583190350187252536@xxx Sun Nov 05 02:12:54 +0000 2017 X-GM-THRID: 1583062957116903258 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread