From patchwork Sun Jun 27 11:54:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 467944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08106C49EAF for ; Sun, 27 Jun 2021 11:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E69EA619BE for ; Sun, 27 Jun 2021 11:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbhF0L5P (ORCPT ); Sun, 27 Jun 2021 07:57:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbhF0L5K (ORCPT ); Sun, 27 Jun 2021 07:57:10 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 606B5C061766 for ; Sun, 27 Jun 2021 04:54:45 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id m14so20899134edp.9 for ; Sun, 27 Jun 2021 04:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Edf+tNNF3bAWLChiP/XQGcKno3Pvtq/MrCmR6QJoexs=; b=CvJK1waDZsD1by/0+/hQtINXYBssR1XKzsZrE73MO/U0tPN/MKduRJwBaXtQM69Jlq ZneIiuPUfZGyHJVwO46UrjddD2o7DwczbJmFYVY4E44yEMW3zEEdWPa2Okn1xNgs3AGE FEKmHr8v5vgDpGYzJZ2/qHrTrnnKE2Chl7ZrsAJIT1DU2i95zxcjLmaOi0RoTElXBcBL mkcA80J4XBbspZtTQFbJiKAj6ghy7QiF1CKGsKZQRpP3+HOIbOL4J7lemNlMthJGA56F XLN+3a0CSHyNkmH6Fms0uyrHmk/ujABYqaEqnjcfEQorj7oe0TQwIebKEvxKtfgSRxBV MNFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Edf+tNNF3bAWLChiP/XQGcKno3Pvtq/MrCmR6QJoexs=; b=J4G1oAYFywZ5HL0BMbKHCr0YCz9M3fWwp/fM9ma9OVvvGE6YsE7fWdG/JNAcmRRjkf KQBEIeU5kb08yaf1WTY7ILIn1ob29OSsnKPBnYAGkNH59uzt9Vlw4nW3+t51HekXc858 F6BuE1ytY85DDh9tCiEsJ4c1XSrnZipKaJAl1PfKdp+3KtUPePdvsBJ9EF9ihQuRmfkJ 6Hz/VSZ8mIqt2s8SQyPkgFv/mLcwG4pV6P5VKpgIQLqH7L48Y9drFIenSw3yiCkybxTt HMhIRZo15KxCfwjzP/rAy2y3gF3B7++anWTqS5W1bNP/2Q3hy9iYLPtqRmARDoCbthLv Q6uA== X-Gm-Message-State: AOAM533lyziI7TYEYsjkfnVfZzLul0qH6sDlxBKejN0u82TvamL3xLXL qv/ZUIWZaK+ZXGlkkUznww4= X-Google-Smtp-Source: ABdhPJzdIgKRtT0tLrJGxZUz+poq+oWE8G2omSX3L+hQjezzzVormf0UYjaHY6gTQAHeZqCOXAdAbw== X-Received: by 2002:a05:6402:1d56:: with SMTP id dz22mr27182877edb.376.1624794884034; Sun, 27 Jun 2021 04:54:44 -0700 (PDT) Received: from localhost.localdomain ([188.26.224.68]) by smtp.gmail.com with ESMTPSA id s4sm7683688edu.49.2021.06.27.04.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 04:54:43 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Tobias Waldekranz , Jiri Pirko , Ido Schimmel , Roopa Prabhu , Nikolay Aleksandrov , Vladimir Oltean Subject: [PATCH v2 net-next 7/8] net: dsa: refactor the prechangeupper sanity checks into a dedicated function Date: Sun, 27 Jun 2021 14:54:28 +0300 Message-Id: <20210627115429.1084203-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210627115429.1084203-1-olteanv@gmail.com> References: <20210627115429.1084203-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Vladimir Oltean We need to add more logic to the DSA NETDEV_PRECHANGEUPPER event handler, more exactly we need to request an unsync of switchdev objects. In order to fit more code, refactor the existing logic into a helper. Signed-off-by: Vladimir Oltean --- v1->v2: patch is new net/dsa/slave.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 2f0d0a6b1f9c..20d8466d78f2 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2166,6 +2166,32 @@ dsa_slave_check_8021q_upper(struct net_device *dev, return NOTIFY_DONE; } +static int +dsa_slave_prechangeupper_sanity_check(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct dsa_switch *ds; + struct dsa_port *dp; + int err; + + if (!dsa_slave_dev_check(dev)) + return dsa_prevent_bridging_8021q_upper(dev, info); + + dp = dsa_slave_to_port(dev); + ds = dp->ds; + + if (ds->ops->port_prechangeupper) { + err = ds->ops->port_prechangeupper(ds, dp->index, info); + if (err) + return notifier_from_errno(err); + } + + if (is_vlan_dev(info->upper_dev)) + return dsa_slave_check_8021q_upper(dev, info); + + return NOTIFY_DONE; +} + static int dsa_slave_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { @@ -2174,24 +2200,12 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, switch (event) { case NETDEV_PRECHANGEUPPER: { struct netdev_notifier_changeupper_info *info = ptr; - struct dsa_switch *ds; - struct dsa_port *dp; int err; - if (!dsa_slave_dev_check(dev)) - return dsa_prevent_bridging_8021q_upper(dev, ptr); - - dp = dsa_slave_to_port(dev); - ds = dp->ds; - - if (ds->ops->port_prechangeupper) { - err = ds->ops->port_prechangeupper(ds, dp->index, info); - if (err) - return notifier_from_errno(err); - } + err = dsa_slave_prechangeupper_sanity_check(dev, info); + if (err != NOTIFY_DONE) + return err; - if (is_vlan_dev(info->upper_dev)) - return dsa_slave_check_8021q_upper(dev, ptr); break; } case NETDEV_CHANGEUPPER: