Received: by 10.223.164.202 with SMTP id h10csp717268wrb; Mon, 6 Nov 2017 14:18:38 -0800 (PST) X-Google-Smtp-Source: ABhQp+Sx/lwUiVVIDmz0skWE7oufQcHMpnckk/bF8VCrgf2k7R1z6Wj3IKMZxSUVLMOS3VUWVOgD X-Received: by 10.101.88.203 with SMTP id e11mr16774812pgu.173.1510006718781; Mon, 06 Nov 2017 14:18:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510006718; cv=none; d=google.com; s=arc-20160816; b=qLOEBnuRl6EnImcKqQzxqYcHCI+m2c4g6acdwAM/Rl60W1EhyJCEvUwJnxrTYvGBev I2OcdVYdKszMqL5wX7LASJNdIa5dIRpFbLAJ73ol2BwYcPv+dJIDo+XvrDOPYK2l1Un/ fSP7HBUjA9W2hiMfCpOjrTepE4G6ElX1mXF7q3v/pM2Es516xt7iBwUNAV2a21867RMB 3+3v5fNDUnrB8M62e5RGBzGX9GTJEBO+IyLS6eIxuEhBdoPHvMszWkXW8MEnYOeYV8AX 0uddLvg+9+3DTTNwlfVCNgxI6JhkJ5KZloy0aBVLn5uahrpj2u4uuv94V8+dRIoMIXBo 27Fw== 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=b27Rl2szZLb9i99ZPCyITd74Li5B94zB5koRdDw2gwQ=; b=ZmgXbQIeem0zaOo2nUDDckTDSoGF9cdx3sVLYEsDAsO9iFGGWkjDwdYZ9G1xu18++3 JzBiQGs3fezJD8Yvz8VnzsRE2MwqCAqvdcdlpEawq09pRqrRGE71yk0+fXvNdJBTHoPl VaFUcUPFIkO+FE2S3IGdWd0oZl2+qtW3snDa1uE2o0XzAFnUxUiBuUCCidK4h3cqrnPz x3RxJnl4wuvhfGbuDOmXqvUi9FcLBBQxPI5tRVQMAas6jVuYZqImYCAiB5P8VzTlBeVX RfoW7DnyXQ4sQRMWcpyxPy8gSPmh81NFSsHgcXIbhNjN9EbJGTxrLaC7YlwSXroanBPC rHEQ== 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 v9si12020381pgt.770.2017.11.06.14.18.25; Mon, 06 Nov 2017 14:18:38 -0800 (PST) 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 S1751867AbdKFVNd (ORCPT + 95 others); Mon, 6 Nov 2017 16:13:33 -0500 Received: from mail.savoirfairelinux.com ([208.88.110.44]:55194 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753689AbdKFVMT (ORCPT ); Mon, 6 Nov 2017 16:12:19 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 899749C2EA9; Mon, 6 Nov 2017 16:12:18 -0500 (EST) 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 IEPRfE29j-7r; Mon, 6 Nov 2017 16:12:18 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 9880D9C1A57; Mon, 6 Nov 2017 16:12:16 -0500 (EST) 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 stg9tgyXYUe0; Mon, 6 Nov 2017 16:12:16 -0500 (EST) Received: from weeman.mtl.sfl (unknown [192.168.49.104]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 475609C1BAA; Mon, 6 Nov 2017 16:12:16 -0500 (EST) 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 10/11] net: dsa: setup a tree when adding a switch to it Date: Mon, 6 Nov 2017 16:11:52 -0500 Message-Id: <20171106211153.26529-11-vivien.didelot@savoirfairelinux.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171106211153.26529-1-vivien.didelot@savoirfairelinux.com> References: <20171106211153.26529-1-vivien.didelot@savoirfairelinux.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that the tree setup is centralized, we can simplify the code a bit more by setting up or tearing down the tree directly when adding or removing a switch to/from it. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 44d26b5977cd..3db50e68640e 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -489,6 +489,8 @@ static void dsa_tree_teardown(struct dsa_switch_tree *dst) static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, unsigned int index) { + dsa_tree_teardown(dst); + dst->ds[index] = NULL; dsa_tree_put(dst); } @@ -497,6 +499,7 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, struct dsa_switch *ds) { unsigned int index = ds->index; + int err; if (dst->ds[index]) return -EBUSY; @@ -504,7 +507,11 @@ static int dsa_tree_add_switch(struct dsa_switch_tree *dst, dsa_tree_get(dst); dst->ds[index] = ds; - return 0; + err = dsa_tree_setup(dst); + if (err) + dsa_tree_remove_switch(dst, index); + + return err; } static int dsa_port_parse_user(struct dsa_port *dp, const char *name) @@ -704,12 +711,17 @@ static int dsa_switch_parse(struct dsa_switch *ds, struct dsa_chip_data *cd) return dsa_switch_parse_ports(ds, cd); } +static int dsa_switch_add(struct dsa_switch *ds) +{ + struct dsa_switch_tree *dst = ds->dst; + + return dsa_tree_add_switch(dst, ds); +} + static int _dsa_register_switch(struct dsa_switch *ds) { struct dsa_chip_data *pdata = ds->dev->platform_data; struct device_node *np = ds->dev->of_node; - struct dsa_switch_tree *dst; - unsigned int index; int err; if (np) @@ -722,20 +734,7 @@ static int _dsa_register_switch(struct dsa_switch *ds) if (err) return err; - index = ds->index; - dst = ds->dst; - - err = dsa_tree_add_switch(dst, ds); - if (err) - return err; - - err = dsa_tree_setup(dst); - if (err) { - dsa_tree_teardown(dst); - dsa_tree_remove_switch(dst, index); - } - - return err; + return dsa_switch_add(ds); } struct dsa_switch *dsa_switch_alloc(struct device *dev, size_t n) @@ -777,8 +776,6 @@ static void _dsa_unregister_switch(struct dsa_switch *ds) struct dsa_switch_tree *dst = ds->dst; unsigned int index = ds->index; - dsa_tree_teardown(dst); - dsa_tree_remove_switch(dst, index); } -- 2.14.3 From 1583352202296935331@xxx Mon Nov 06 21:05:29 +0000 2017 X-GM-THRID: 1583352202296935331 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread