From patchwork Wed May 23 01:38:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 10420009 X-Patchwork-Delegate: idosch@idosch.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 19044600CC for ; Wed, 23 May 2018 01:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07BEA28DA6 for ; Wed, 23 May 2018 01:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC45728ED1; Wed, 23 May 2018 01:40:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7DBC28DA3 for ; Wed, 23 May 2018 01:40:01 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40rFZ76VmszDrbk for ; Wed, 23 May 2018 11:39:59 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="pYhIDsxF"; dkim-atps=neutral X-Original-To: linux-mlxsw@lists.ozlabs.org Delivered-To: linux-mlxsw@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mellanox.com (client-ip=104.47.2.40; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=petrm@mellanox.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=mellanox.com Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=Mellanox.com header.i=@Mellanox.com header.b="pYhIDsxF"; dkim-atps=neutral Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0040.outbound.protection.outlook.com [104.47.2.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40rFZ14xFdzDrTs for ; Wed, 23 May 2018 11:39:52 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9vrvNq3e82oLunYDYY9nIsoNhP4+YR7sUGkgGUybR4E=; b=pYhIDsxFNErepqnGHSG+M55uvuY6p5JAOiMtR35LNVzpkl457DUtojdbeigskntq76YNyi1FeMrfKUmxsDJG7ZhOjpI4pRWMpIHaxQIUpwI5ndPLo2w1fw0e99HSEZruX++EidI7w1Qy/whl5E7kWde9BrDF1q8nJKtaXveTJVo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=petrm@mellanox.com; Received: from t540p (89.176.83.59) by AM6PR05MB4183.eurprd05.prod.outlook.com (2603:10a6:209:40::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.797.11; Wed, 23 May 2018 01:39:48 +0000 From: Petr Machata To: Subject: [PATCH net-next mlxsw 1/7] net: bridge: Extract boilerplate around switchdev_port_obj_*() In-Reply-To: References: Message-Id: <5e54389e0ace71fd8803d3acbe1132abe13e8772.1527039181.git.petrm@mellanox.com> Date: Wed, 23 May 2018 03:38:59 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 X-Originating-IP: [89.176.83.59] X-ClientProxiedBy: LO2P265CA0034.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::22) To AM6PR05MB4183.eurprd05.prod.outlook.com (2603:10a6:209:40::28) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:AM6PR05MB4183; X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4183; 3:57CeSoPyp3ZfjVM+dIz9o/vHYBEXnTXZU/XG92Wl2ycjykCOspKlMRUf4QwUaeiwIP/6NvSCy87IbJ8dt0SqtHSHI1fG/lOdFU0MxD3Rp3SeDNQ0WWZxX+EExiX6hWSUErUPgQMOOEXM4Nb6divRbsBuyHGq5bamX9puIcnyEa36/7kJUvD8Yvs0eh5395PzrfNfEIEicODjWEBjtq418ZnYR0XBKyK4F+Hva9JF3OPTUiMDva8b0LuVRgSnObml; 25:doNEL7m7VeEqxNHNUU2gJsY//uOXMvagHj1zaz9wslF+D0RBeP6WJCeTqZcgbtSSoNJxlQegmOE3ZNT75s0mUJHOCsRQYK21F/XWP+Gj4EZi+/pZOTRl6Th++WRf+2DMbmUmqmrAVdQozPESK9idaXGv13Gj6psnmdkfgBxZumL5dGuSvzRoY/GFARKFZN1XLk+CuvayfVxRW/QNflg6q4BLC046D4mKV/hvIitqG3UUvVOtYb7Ub3xSpRPZ7sydDuJBNFRhQQTFhXun4EQCzv6a6HAcGcBVzwC7QIVWEqMswViHqFK9l0cv8BeV3Sqaa46+ISXjd/OxnPu/xkH1Nw==; 31:C5luBlPcd5mtwPkTgaIpXhQIyQVIoLTOMyE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Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(3002001)(6055026)(149027)(150027)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:AM6PR05MB4183; BCL:0; PCL:0; RULEID:; SRVR:AM6PR05MB4183; X-Forefront-PRVS: 06818431B9 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(39380400002)(39860400002)(376002)(346002)(396003)(199004)(189003)(52116002)(186003)(53936002)(76176011)(51416003)(6486002)(6862004)(2351001)(86362001)(26005)(58126008)(37006003)(316002)(386003)(16586007)(478600001)(6116002)(3846002)(5660300001)(97736004)(118296001)(81166006)(81156014)(8676002)(7736002)(305945005)(68736007)(8936002)(66066001)(6636002)(6666003)(6496006)(36756003)(47776003)(105586002)(106356001)(2906002)(476003)(48376002)(956004)(2616005)(486006)(11346002)(50466002)(25786009)(446003)(16526019); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR05MB4183; H:t540p; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR05MB4183; 23:rokw3zPD7LxjyDJLTelqHF7HqYU5idAxXrbiRW+kk?= =?us-ascii?Q?Y/lbMmHmGwsRPWMYgBqJDONMVJ2dGkCodouII1enxB55+AN2umnPS9DSPk0l?= =?us-ascii?Q?GdiVIrOtw5SB11ifjxQ3FvkbaYLCAZ3x8N8n0zET0buQzR7wt+gOUBW65xbx?= =?us-ascii?Q?pOdqfDYeppCQTRSBzJruSjksE7Nl1IwIX2W+dDoooIwOBIXRH+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xjOFZdFeJ5oJZSAIPMi5Z+KeTg/Uv5XUx/IBcAaK4YQ=; 24:Y4Vu65PMP1armFJqrjzsrjm0ldATcNC092oGi8InP9A7opPpT4Ahj3kkabPhViYPVZajEXxOPVCfsWW6tRh7URg25S+6buv4P5F7+CBZjGE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM6PR05MB4183; 7:VUDjFFe+6KonSsD3/WhAVurDTFhTEBViSe4YGi4pNjSxGtqPIr59XarMBeil6wPJM6AGmc6z39pVzyXAMeGwS3R+X1gdzuqmFheZ/3XWJmmyruK+dfcduifBuasJtO8hcywHOkfW9bZ0FKObFN3l05TZFlmALBMylhHi2Qwauec7WQLLVEeMhqQaEvJ/paZ8IYd3iIdJBwONOUeXXYpRR60I/On+IEHaQ1/h1KxL++YeueUXye53HsvKuaEBSSps X-MS-Office365-Filtering-Correlation-Id: 44e14583-fcbf-41ce-6627-08d5c04e11e2 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2018 01:39:48.0793 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44e14583-fcbf-41ce-6627-08d5c04e11e2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR05MB4183 X-BeenThere: linux-mlxsw@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: mlxsw driver development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-mlxsw-bounces+patchwork-linux-mlxsw=patchwork.kernel.org@lists.ozlabs.org X-Virus-Scanned: ClamAV using ClamSMTP A call to switchdev_port_obj_add() or switchdev_port_obj_del() involves initializing a struct switchdev_obj_port_vlan, a piece of code that repeats on each call site almost verbatim. While in the current codebase there is just one duplicated add call, the follow-up patches add more of both add and del calls. Thus to remove the duplication, extract the repetition into named functions and reuse. Signed-off-by: Petr Machata --- net/bridge/br_vlan.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index dc832c09..a75fe930 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -79,8 +79,7 @@ static bool __vlan_add_flags(struct net_bridge_vlan *v, u16 flags) return ret || !!(old_flags ^ v->flags); } -static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, - u16 vid, u16 flags) +static int br_switchdev_port_obj_add(struct net_device *dev, u16 vid, u16 flags) { struct switchdev_obj_port_vlan v = { .obj.orig_dev = dev, @@ -89,12 +88,29 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, .vid_begin = vid, .vid_end = vid, }; - int err; + return switchdev_port_obj_add(dev, &v.obj); +} + +static int br_switchdev_port_obj_del(struct net_device *dev, u16 vid) +{ + struct switchdev_obj_port_vlan v = { + .obj.orig_dev = dev, + .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, + .vid_begin = vid, + .vid_end = vid, + }; + + return switchdev_port_obj_del(dev, &v.obj); +} + +static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, + u16 vid, u16 flags) +{ /* Try switchdev op first. In case it is not supported, fallback to * 8021q add. */ - err = switchdev_port_obj_add(dev, &v.obj); + int err = br_switchdev_port_obj_add(dev, vid, flags); if (err == -EOPNOTSUPP) return vlan_vid_add(dev, br->vlan_proto, vid); return err; @@ -130,18 +146,11 @@ static void __vlan_del_list(struct net_bridge_vlan *v) static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, u16 vid) { - struct switchdev_obj_port_vlan v = { - .obj.orig_dev = dev, - .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, - .vid_begin = vid, - .vid_end = vid, - }; - int err; - /* Try switchdev op first. In case it is not supported, fallback to * 8021q del. */ - err = switchdev_port_obj_del(dev, &v.obj); + int err = br_switchdev_port_obj_del(dev, vid); + if (err == -EOPNOTSUPP) { vlan_vid_del(dev, br->vlan_proto, vid); return 0; @@ -1053,13 +1062,6 @@ int nbp_vlan_init(struct net_bridge_port *p) int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, bool *changed) { - struct switchdev_obj_port_vlan v = { - .obj.orig_dev = port->dev, - .obj.id = SWITCHDEV_OBJ_ID_PORT_VLAN, - .flags = flags, - .vid_begin = vid, - .vid_end = vid, - }; struct net_bridge_vlan *vlan; int ret; @@ -1069,7 +1071,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, vlan = br_vlan_find(nbp_vlan_group(port), vid); if (vlan) { /* Pass the flags to the hardware bridge */ - ret = switchdev_port_obj_add(port->dev, &v.obj); + ret = br_switchdev_port_obj_add(port->dev, vid, flags); if (ret && ret != -EOPNOTSUPP) return ret; *changed = __vlan_add_flags(vlan, flags);