From patchwork Sat Jan 16 00:59:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12024457 X-Patchwork-Delegate: kuba@kernel.org 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 39999C433E6 for ; Sat, 16 Jan 2021 01:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF37223A3C for ; Sat, 16 Jan 2021 01:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728773AbhAPBB6 (ORCPT ); Fri, 15 Jan 2021 20:01:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727798AbhAPBBz (ORCPT ); Fri, 15 Jan 2021 20:01:55 -0500 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 469FAC06179A for ; Fri, 15 Jan 2021 17:00:43 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id p22so11489594edu.11 for ; Fri, 15 Jan 2021 17:00:43 -0800 (PST) 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=n5BibzNtUVWtkQIdfb1fd0X382vN/3t8GEzoEkNaObM=; b=jeUL462tbWbqHVVxoNpbYrJKmeTaJc3rTQQp1sAt+YiVTKvExhVbM/f+LmK8mcQaqF SibUZzCNjJOUmx5ONxQWijySw3Jgn9EifFcmi0HkIAz5CAVL5IqfCYupm+V46L+x8S5Y oe3qiZulG438WEqw/pBY56lWK+E6ydeR87Rl2yVioCkPErVKjCuMOdRcSyD1b0bvOehz lUtZcGKP4sE3o+1JzckHjM4mPosfg5ZFq3ER7F0bcKbYdlHLOWa9RjlcOSKMReAKKDFH MeTDMUZFnj16H/KHUKB2Yvo52ve1lIF2lNIDlSVf0NKdgwx5+5cYoxa56XDY8NUZoMNT iqUA== 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=n5BibzNtUVWtkQIdfb1fd0X382vN/3t8GEzoEkNaObM=; b=SZI0WcbCVYiS3wd6wYdZgWnNMebqxyGUPYzxAeYtpKHewYOUsPk9/P6ZAAxqXaKdLq /PKyVM4gOa8VrZDnb7C8z3ItY8MnrXgd+zFJZkHzJvzRAUQR34r6iFbmSgw6n3AoK7d6 D/NyXmuecQrPi40gYb1Ci/wCNHkFbxsPjYzRzVVDEm1Fa9ysitNNv/Y/T5FD05cBTcUv O7kwurN/zm3AwjLkkVZ+Nl+Xb/clh1UCgenN0daSNnm1PBtIjS5s3sG1CpTeQEIIuwtb ZU8hv0xWXkO8pIHqDGLZyor96YYHPHDDOdSaXTabo1LVWoew25gGS0bVqn4Vyvn39bBJ dBpg== X-Gm-Message-State: AOAM533a2ef4YFcmCbdr87zcs86pBukDZOFtNl37nC3g447Mrzn8lM8H M3DENjSWpZUS+RvS6li2o5s= X-Google-Smtp-Source: ABdhPJzmSP5a1agOgZAfAOKuhXQ3wDuWvUaJ8Pn7vPxZhPUwWxijfoymMSUM/DH3PzBfRq+NVxgJIg== X-Received: by 2002:a50:b246:: with SMTP id o64mr11104151edd.132.1610758842032; Fri, 15 Jan 2021 17:00:42 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id k3sm5666655eds.87.2021.01.15.17.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 17:00:41 -0800 (PST) From: Vladimir Oltean To: "David S . Miller" , Jakub Kicinski Cc: netdev , Microchip Linux Driver Support , Alexandre Belloni , Andrew Lunn , Florian Fainelli , Vivien Didelot , Claudiu Manoil , Tobias Waldekranz , Maxim Kochetkov Subject: [PATCH v2 net-next 07/14] net: mscc: ocelot: avoid unneeded "lp" variable in LAG join Date: Sat, 16 Jan 2021 02:59:36 +0200 Message-Id: <20210116005943.219479-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210116005943.219479-1-olteanv@gmail.com> References: <20210116005943.219479-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The index of the LAG is equal to the logical port ID that all the physical port members have, which is further equal to the index of the first physical port that is a member of the LAG. The code gets a bit carried away with logic like this: if (a == b) c = a; else c = b; which can be simplified, of course, into: c = b; (with a being port, b being lp, c being lag) This further makes the "lp" variable redundant, since we can use "lag" everywhere where "lp" (logical port) was used. So instead of a "c = b" assignment, we can do a complete deletion of b. Only one comment here: if (bond_mask) { lp = __ffs(bond_mask); ocelot->lags[lp] = 0; } lp was clobbered before, because it was used as a temporary variable to hold the new smallest port ID from the bond. Now that we don't have "lp" any longer, we'll just avoid the temporary variable and zeroize the bonding mask directly. Signed-off-by: Vladimir Oltean Reviewed-by: Alexandre Belloni --- Changes in v2: None. drivers/net/ethernet/mscc/ocelot.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index e2744b921a97..ce52bf892f9b 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1273,7 +1273,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, struct netdev_lag_upper_info *info) { u32 bond_mask = 0; - int lag, lp; + int lag; if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) return -EOPNOTSUPP; @@ -1282,22 +1282,18 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, bond_mask = ocelot_get_bond_mask(ocelot, bond); - lp = __ffs(bond_mask); + lag = __ffs(bond_mask); /* If the new port is the lowest one, use it as the logical port from * now on */ - if (port == lp) { - lag = port; + if (port == lag) { ocelot->lags[port] = bond_mask; bond_mask &= ~BIT(port); - if (bond_mask) { - lp = __ffs(bond_mask); - ocelot->lags[lp] = 0; - } + if (bond_mask) + ocelot->lags[__ffs(bond_mask)] = 0; } else { - lag = lp; - ocelot->lags[lp] |= BIT(port); + ocelot->lags[lag] |= BIT(port); } ocelot_setup_lag(ocelot, lag);