Received: by 10.223.164.221 with SMTP id h29csp355074wrb; Fri, 3 Nov 2017 16:07:32 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QXKiFjdN3hqvhhWlXvzghlLKyG/XI6n3aEG1B63Gl2XgAlPW+p4KGOfB3arYE8VEhU4Dn+ X-Received: by 10.98.133.152 with SMTP id m24mr9263042pfk.62.1509750451957; Fri, 03 Nov 2017 16:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509750451; cv=none; d=google.com; s=arc-20160816; b=m+YxYIXj18K98JN2nUcnFRIyNVliSL4L7q3iVnWaBtkSjrkFwpimovDJbsPUFSzxo/ G8vJQwXRjW06PZrAaWeBZKdekvhckE0Hlaf1Ri3v3Wkp7OBmcD2H0JrOsRY9g5Lt6cIb yrKIIo6UjiB4omLvU81o/vI9cdczr9qmgMZZYozZnVWsqW6d9Ovk6U7bs//j15zuIpQj 3IceKUQTHnmOPE+Rfew/Eye31PbovbC2uiVFsEcs7beDCDG68RW/CM7vXCQ/7DwFS49f 7mKZU8bvtwu72r68AGm5+dpDbaMyF3oK2AGWRuHu5d/FK58nAorMUtSfwvCFYAUFM7cZ pa6Q== 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=uasYQ2AMdHvSCDv/sjgFW9fioe0vXehBfMzO38kOOKs=; b=lRqhkquavKCPw/exq2oIaShZh6e/zDIP6W3EYBWbed7aSFRcufoY8fObaZi666TRQR RXuPFXbrSnM40AJ6K14sSAn4r6d7roPedKihRmS8p6BAth9riAoEGNyOmoKW+OrkAnM/ ZYz4X4lcbNHZyAnTDLR+WkN1cGFuUbsyuHEj7rioMBT3AvI4YGufdoz5JVMouvvccaEE 2erJm7my+5nKGq4dyVvuBvMrl2nN+Ow3zv5F/+U6kgzS3JoTnB+dwqXth7/Om8/f/QaE B0UaBsiAqe2G1m+NSXjzGhnX8JWvY5i6wZiXcMpY31+sazGMzIOHKRj2QyCcyRz+WZ8O sl6w== 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 y2si6869382pgo.89.2017.11.03.16.07.19; Fri, 03 Nov 2017 16:07:31 -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 S932676AbdKCXGD (ORCPT + 92 others); Fri, 3 Nov 2017 19:06:03 -0400 Received: from mail.savoirfairelinux.com ([208.88.110.44]:33276 "EHLO mail.savoirfairelinux.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752421AbdKCXF4 (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 E02A29C3022; 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 qifoim8vgHmu; Fri, 3 Nov 2017 19:05:47 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 03F419C2FF6; Fri, 3 Nov 2017 19:05:47 -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 cp5Fe6xANveI; 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 B02CE9C2F69; 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 06/11] net: dsa: rework switch addition and removal Date: Fri, 3 Nov 2017 19:05:25 -0400 Message-Id: <20171103230530.996-7-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 This patch removes the unnecessary index argument from the dsa_dst_add_ds and dsa_dst_del_ds functions and renames them to dsa_tree_add_switch and dsa_tree_remove_switch respectively. In addition to a more explicit scope, we now check the presence of an existing switch with the same index directly within dsa_tree_add_switch. Signed-off-by: Vivien Didelot --- net/dsa/dsa2.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index bda222cfc02c..5b6a3dad8015 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -94,20 +94,6 @@ 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; -} - -static void dsa_dst_del_ds(struct dsa_switch_tree *dst, - struct dsa_switch *ds, u32 index) -{ - dst->ds[index] = NULL; - dsa_tree_put(dst); -} - /* For platform data configurations, we need to have a valid name argument to * differentiate a disabled port from an enabled one */ @@ -484,6 +470,27 @@ static void dsa_dst_unapply(struct dsa_switch_tree *dst) dst->applied = false; } +static void dsa_tree_remove_switch(struct dsa_switch_tree *dst, + unsigned int index) +{ + dst->ds[index] = NULL; + dsa_tree_put(dst); +} + +static int dsa_tree_add_switch(struct dsa_switch_tree *dst, + struct dsa_switch *ds) +{ + unsigned int index = ds->index; + + if (dst->ds[index]) + return -EBUSY; + + dsa_tree_get(dst); + dst->ds[index] = ds; + + return 0; +} + static int dsa_cpu_parse(struct dsa_port *port, u32 index, struct dsa_switch_tree *dst, struct dsa_switch *ds) @@ -762,9 +769,6 @@ static int _dsa_register_switch(struct dsa_switch *ds) if (!dst) return -ENOMEM; - if (dst->ds[index]) - return -EBUSY; - ds->dst = dst; ds->index = index; ds->cd = pdata; @@ -773,7 +777,9 @@ static int _dsa_register_switch(struct dsa_switch *ds) for (i = 0; i < DSA_MAX_SWITCHES; ++i) ds->rtable[i] = DSA_RTABLE_NONE; - dsa_dst_add_ds(dst, ds, index); + err = dsa_tree_add_switch(dst, ds); + if (err) + return err; err = dsa_dst_complete(dst); if (err < 0) @@ -801,7 +807,7 @@ static int _dsa_register_switch(struct dsa_switch *ds) return 0; out_del_dst: - dsa_dst_del_ds(dst, ds, ds->index); + dsa_tree_remove_switch(dst, index); return err; } @@ -843,10 +849,11 @@ EXPORT_SYMBOL_GPL(dsa_register_switch); static void _dsa_unregister_switch(struct dsa_switch *ds) { struct dsa_switch_tree *dst = ds->dst; + unsigned int index = ds->index; dsa_dst_unapply(dst); - dsa_dst_del_ds(dst, ds, ds->index); + dsa_tree_remove_switch(dst, index); } void dsa_unregister_switch(struct dsa_switch *ds) -- 2.14.3 From 1583095285524641858@xxx Sat Nov 04 01:01:54 +0000 2017 X-GM-THRID: 1582999083935096845 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread