Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp801077pxb; Tue, 12 Apr 2022 13:50:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsq33XW2fdZbxlTzjqStGk6kQckWAorAUscd95y0qkEDD/f4MYM6YhoiddSrnZ7QGx16Z/ X-Received: by 2002:a17:90a:4889:b0:1cb:646b:e33a with SMTP id b9-20020a17090a488900b001cb646be33amr6945168pjh.136.1649796658796; Tue, 12 Apr 2022 13:50:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649796658; cv=none; d=google.com; s=arc-20160816; b=XKA/OdeIE812+6nrlRQlIdjjSBtAJfeoY3nxTyddKKGIFuQhn95UzXMxRHLspuarBv CjYNA4J4K2ASg5bdFcO9EJrKceqrC+eUDrBF7B9kiKwakYEHAKaN/uRxX31LhhzvqBRM hbVbhSdY0x4YgwTejWu3nsqR1Q0hNrdhyXj2V86uUvXnB8NGXphE9bMjB5rTdiBK2QmO ll5hiJuLbCCSV5MRmu067KU0jXWzRXvvsBNHvquJ1Egt3VeeZjMAERHd7p2zrg08YVqP zuVBk87KhIEFgbaSjbwzB+mEUH0PCd+h/T6RIQcS1sm9r5IIXR69aBNaQfyHTfAR2HiO uhnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7YEqjlB8bsXZ45gzNCMwH2JxmTxm4dwtRKumhhyyThw=; b=PFvw2LZIKyKfsaXsutij5X9BpfjybfEB9ClQQs6WKjz1loH1X6BrNSC8At5oe3r6t2 7CKLiAlZcjEqKRc7aaBOmVBA2Npy/zZfXDxL7qnchywVutQmD/5SWWFosikVnIA7kXIh 2DKC7BI2rKQG8fd3+kwfq9PtyzMlrGak0Bkwqg7rU0k2fN9x3gms+rsXyqVN/tY5mNpL bSo+081qPuWRo1hHMX93VgsN1UoQe/U2DlwNDmr0MEiIrtfyxIxZ5aOYfjFQpP76WqMR s7ImlS4/0JyLdGps+0YeXDiSA4wcI3OND4cavQNNul8yH4rBiVXZx3t57HCV/MvaPdhN /wwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JuhzPZfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g6-20020a17090a578600b001c9e16e3b0dsi12144944pji.73.2022.04.12.13.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:50:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JuhzPZfb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7CA24C6B6E; Tue, 12 Apr 2022 13:18:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349823AbiDLMF5 (ORCPT + 99 others); Tue, 12 Apr 2022 08:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351597AbiDLMCk (ORCPT ); Tue, 12 Apr 2022 08:02:40 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11D9E5419A; Tue, 12 Apr 2022 03:59:03 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id r13so36579527ejd.5; Tue, 12 Apr 2022 03:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7YEqjlB8bsXZ45gzNCMwH2JxmTxm4dwtRKumhhyyThw=; b=JuhzPZfbHNp8KzizpUd3npS/c+avk0cNSWxtttmDVRhdog+mWS5PTWORph9Q/qUAoM 8keJvj9dv/yXVqmRWakr4m/xQNHJeKAi56tBJb3u/jJ19GjNaDhLDPUv3qF/6xu4bFfc MwZ9KLk6mOmN9CZCuDK1qaSrOu4h7B6TnvJxk+iJzbX6esKmylO5Kk+omrDNnYoOEyoq tymNsbhCDPqH6T97QNozKI1EtoPpIylEEuvUVbarJM6bYztq55mxIufOYzJPwjcnpBkR OxEgQOgUI44VTnd4XOSko8dEfDEyBNc4ttZuNXmLYcBc3CoaDYnAkUBH24mpRu3FH6KP in4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7YEqjlB8bsXZ45gzNCMwH2JxmTxm4dwtRKumhhyyThw=; b=mD8zFAOIyJOiu5vFEzHpXiAF23u5b75DnG/Tfva5nbKC9wfXzUtsgN+L2sVVNhi5s8 qX/31rjgSHcYfOr2w4ooKDDVoAOg8eBL2fMj5XNUOVQIljmLP6hcYtek64pUTL1/xUHh +uVB0JfV7GyiOkx2Et8vMVwkaESPCdvEi8HnJ+/ASuXacqLzZsV8e0kIUmZZO1O2iV4j JsvOLf1ZvPOIam3j+VjpLnrKF7R91uDDreeBYIxwZtb8eCj90UlzoZ5HyflJSkZ9HVlg 3OURlD0DTWq+JpDGk3gjko4Q0pC5waztfj0BYI3GyG3OD1aq+XHFYftPjZzBTTC6ihT5 A8uw== X-Gm-Message-State: AOAM530CskMM0+FwVL6i5WdN+wIweEWpz0Afd5h8SnL+DFavGjNfg8oZ lEFScV6y0N7cJ4M2GWyYKzg= X-Received: by 2002:a17:907:7f1b:b0:6e8:558c:5ba with SMTP id qf27-20020a1709077f1b00b006e8558c05bamr18626088ejc.522.1649761142286; Tue, 12 Apr 2022 03:59:02 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id f1-20020a056402194100b00416b174987asm16986370edz.35.2022.04.12.03.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:59:01 -0700 (PDT) From: Jakob Koschel To: "David S. Miller" Cc: Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Edward Cree , Martin Habets , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jiri Pirko , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Casper Andersson , Jakob Koschel , Colin Ian King , Arnd Bergmann , Michael Walle , Christophe JAILLET , Eric Dumazet , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, bpf@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH net-next v2 08/18] net: sparx5: Replace usage of found with dedicated list iterator variable Date: Tue, 12 Apr 2022 12:58:20 +0200 Message-Id: <20220412105830.3495846-9-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220412105830.3495846-1-jakobkoschel@gmail.com> References: <20220412105830.3495846-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- .../microchip/sparx5/sparx5_mactable.c | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c index a5837dbe0c7e..bb8d9ce79ac2 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c @@ -362,8 +362,7 @@ static void sparx5_mact_handle_entry(struct sparx5 *sparx5, unsigned char mac[ETH_ALEN], u16 vid, u32 cfg2) { - struct sparx5_mact_entry *mact_entry; - bool found = false; + struct sparx5_mact_entry *mact_entry = NULL, *iter; u16 port; if (LRN_MAC_ACCESS_CFG_2_MAC_ENTRY_ADDR_TYPE_GET(cfg2) != @@ -378,28 +377,28 @@ static void sparx5_mact_handle_entry(struct sparx5 *sparx5, return; mutex_lock(&sparx5->mact_lock); - list_for_each_entry(mact_entry, &sparx5->mact_entries, list) { - if (mact_entry->vid == vid && - ether_addr_equal(mac, mact_entry->mac)) { - found = true; - mact_entry->flags |= MAC_ENT_ALIVE; - if (mact_entry->port != port) { + list_for_each_entry(iter, &sparx5->mact_entries, list) { + if (iter->vid == vid && + ether_addr_equal(mac, iter->mac)) { + iter->flags |= MAC_ENT_ALIVE; + if (iter->port != port) { dev_warn(sparx5->dev, "Entry move: %d -> %d\n", - mact_entry->port, port); - mact_entry->port = port; - mact_entry->flags |= MAC_ENT_MOVED; + iter->port, port); + iter->port = port; + iter->flags |= MAC_ENT_MOVED; } /* Entry handled */ + mact_entry = iter; break; } } mutex_unlock(&sparx5->mact_lock); - if (found && !(mact_entry->flags & MAC_ENT_MOVED)) + if (mact_entry && !(mact_entry->flags & MAC_ENT_MOVED)) /* Present, not moved */ return; - if (!found) { + if (!mact_entry) { /* Entry not found - now add */ mact_entry = alloc_mact_entry(sparx5, mac, vid, port); if (!mact_entry) -- 2.25.1