Received: by 10.223.164.221 with SMTP id h29csp356351wrb; Fri, 3 Nov 2017 16:09:20 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QALGRaZbw7QWpxOfsvVa1VW+7o/At+Oh+/LWZmPFyK7Oo2GLRUmSP5P2mRBGqhnXl+MqLR X-Received: by 10.84.135.101 with SMTP id 92mr8297200pli.180.1509750560427; Fri, 03 Nov 2017 16:09:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509750560; cv=none; d=google.com; s=arc-20160816; b=lgjHclIOOpXwdQooYVqRQKrpGNTyyBwOxWOa/2IiPMezbjMgqOejZhTsPffXa6we9+ FPJri2wa9WUyiI0spzPXb6KUbZfc6o9vAiLeRFaYw8k8h5f4HjCXkPYiKCCacgkSLJc+ 5TGZ9/zBgcB9dqhFaSRpgio++InstDmyTJyfippJIKbDMYW3mi725mBSS78RdrdGLadW a7aBxUKl19OlKaSzbZ9u0l47SCYe5/0eQNm0Ys6eTYw+cYoStNO2ylPCpAxv2xoSp/73 z1OwGXKwIe/5mko8wz3gpzRTU/SDDqQJ2pn7b3akYcLzXqatSdyELBbtkjWnI3C+EAU4 CVxg== 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=Fx7IEV9r1SvN3ksGVlS7R0SGohohG/MVIt6zHBMnTKU=; b=0x31E4wkPPlVzMmsxNGRoH2ckCYwmt4WP6YpoBTp5IWBSgqbKOxXgjbFz6VXeKR+E2 UtTq/Y5nP2znP7HkYc2Kv67yIL6mo1MTA9nQGVKlie/xoxTankPcm07nQz0oztp2skEv +5Gy73y+V5SEx2ugofDv4njhHOXA+O2bScv7ToO7df2rhDBvRqjj8nExfyGkWWScysDs ZebIxUh5aZ+gupMnxNhot9IJiDNM4GDONRhgtxnFbYC0mPs8USR7215En5h8uDkrw99C +dvl/tolgzh+h0gbCOOqhtbQh1DlKb0kUrLSTlxbq8iOvzGNDNC8PcdPEENfrH3ABDSg ZG3g== 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 m15si6756172pgs.719.2017.11.03.16.09.07; Fri, 03 Nov 2017 16:09:20 -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 S1756482AbdKCXGA (ORCPT + 92 others); Fri, 3 Nov 2017 19:06:00 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:33304 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756247AbdKCXF5 (ORCPT ); Fri, 3 Nov 2017 19:05:57 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 0BD059C2F53; Fri, 3 Nov 2017 19:05:57 -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 bszsmDW-nq5h; Fri, 3 Nov 2017 19:05:49 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id E6A7A9C2F4D; 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 l2AxR-CKqw5h; 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 A56799C2F01; 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 05/11] net: dsa: provide a find or new tree helper Date: Fri, 3 Nov 2017 19:05:24 -0400 Message-Id: <20171103230530.996-6-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 Rename dsa_get_dst to dsa_tree_find since it doesn't increment the reference counter, rename dsa_add_dst to dsa_tree_alloc for symmetry with dsa_tree_free, and provide a convenient dsa_tree_touch function to find or allocate a new tree. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 609d92684505..bda222cfc02c 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -21,33 +21,35 @@ #include "dsa_priv.h" -static LIST_HEAD(dsa_switch_trees); +static LIST_HEAD(dsa_tree_list); static DEFINE_MUTEX(dsa2_mutex); static const struct devlink_ops dsa_devlink_ops = { }; -static struct dsa_switch_tree *dsa_get_dst(unsigned int index) +static struct dsa_switch_tree *dsa_tree_find(int index) { struct dsa_switch_tree *dst; - list_for_each_entry(dst, &dsa_switch_trees, list) + list_for_each_entry(dst, &dsa_tree_list, list) if (dst->index == index) return dst; return NULL; } -static struct dsa_switch_tree *dsa_add_dst(unsigned int index) +static struct dsa_switch_tree *dsa_tree_alloc(int index) { struct dsa_switch_tree *dst; dst = kzalloc(sizeof(*dst), GFP_KERNEL); if (!dst) return NULL; + dst->index = index; + INIT_LIST_HEAD(&dst->list); - list_add_tail(&dsa_switch_trees, &dst->list); + list_add_tail(&dsa_tree_list, &dst->list); /* Initialize the reference counter to the number of switches, not 1 */ kref_init(&dst->refcount); @@ -62,6 +64,17 @@ static void dsa_tree_free(struct dsa_switch_tree *dst) kfree(dst); } +static struct dsa_switch_tree *dsa_tree_touch(int index) +{ + struct dsa_switch_tree *dst; + + dst = dsa_tree_find(index); + if (!dst) + dst = dsa_tree_alloc(index); + + return dst; +} + static void dsa_tree_get(struct dsa_switch_tree *dst) { kref_get(&dst->refcount); @@ -745,12 +758,9 @@ static int _dsa_register_switch(struct dsa_switch *ds) return err; } - dst = dsa_get_dst(tree); - if (!dst) { - dst = dsa_add_dst(tree); - if (!dst) - return -ENOMEM; - } + dst = dsa_tree_touch(tree); + if (!dst) + return -ENOMEM; if (dst->ds[index]) return -EBUSY; -- 2.14.3 From 1583099133863954996@xxx Sat Nov 04 02:03:04 +0000 2017 X-GM-THRID: 1580545391358415129 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread