From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7BA0C433F5 for ; Thu, 28 Apr 2022 09:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbiD1JtN (ORCPT ); Thu, 28 Apr 2022 05:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347959AbiD1Jfx (ORCPT ); Thu, 28 Apr 2022 05:35:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 18BC19548B for ; Thu, 28 Apr 2022 02:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651138359; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OG6hUPY6sAUTqTJViKJ1E1LWjNyEwooQAig3aG1iSlg=; b=cdoei2hJcSbHuHkYZQ3MvgS8axm0jut80Hqzf014rP13NYK2DibnzS+WZwyUSUWh+ODxEc o7onngKKqisVXVVI8w7dfaBqYGc5CQU80N+R3Zn60/Mh03JYd2kL6neHZLRNmTmElkawc4 NuBRgM6eEICO7jQAST6tKQuCxF/kbgE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-618-CzAHaEGHOGeH_Iyu-boiIA-1; Thu, 28 Apr 2022 05:32:37 -0400 X-MC-Unique: CzAHaEGHOGeH_Iyu-boiIA-1 Received: by mail-qk1-f199.google.com with SMTP id u7-20020ae9d807000000b00680a8111ef6so2830502qkf.17 for ; Thu, 28 Apr 2022 02:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=OG6hUPY6sAUTqTJViKJ1E1LWjNyEwooQAig3aG1iSlg=; b=XFs3SvfkbnhKEjvww/xH13I6Fe++3rrsiJKRoZcNEPdPHqZ+sPgVw049PUO599v/Y9 NmhozVnkSEGzqDFdIOaiGu0cAN+4Bu/Jl3J3IkfpXa7S/KZ26vhXfZnr508AP0UNtS31 9kyWGL1CXLeGOPbxy+6plE90jczvc2ybvQIWVOplcRKO1pr7tTgqqippR/OEgG/iZ874 YaZXO3m4xnDJWLAHNBMpNCcEePVh2tPPi6eqLWJvL28pVNf3BWZjd+eR8FJCCfrjG7A1 izM/usUy776BtuIvhiLZ+nXcCaBIPkVuz22Q4I3yki7UIJtAQr+TtE0bBgcr/YbpoZwx +dmA== X-Gm-Message-State: AOAM532D3qa7bqt91eDUD0AGRrnVNAVtVfqxcamGHbJUkfGQLAHAM8Dg zFoUhi63jGp1a22NodtPZKRLXLo9k9T2pQ2Wx5aYKofaQ1iLTbGzSxqdr9NdeaLCfAhXFtG0uyL BZpTJN2kwd2teB0v+sNccoa9m X-Received: by 2002:a05:622a:2cb:b0:2f3:646b:54b6 with SMTP id a11-20020a05622a02cb00b002f3646b54b6mr15456758qtx.380.1651138356462; Thu, 28 Apr 2022 02:32:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJ3J0ImF+LM/cJTr/TdEmv6YBtIqlv1bBiDK6w9j0coe0CvNV+LL3YO5hh7fcCBb3x5O7y0w== X-Received: by 2002:a05:622a:2cb:b0:2f3:646b:54b6 with SMTP id a11-20020a05622a02cb00b002f3646b54b6mr15456733qtx.380.1651138356147; Thu, 28 Apr 2022 02:32:36 -0700 (PDT) Received: from gerbillo.redhat.com (146-241-117-160.dyn.eolo.it. [146.241.117.160]) by smtp.gmail.com with ESMTPSA id k66-20020a37ba45000000b0069c5adb2f2fsm9620433qkf.6.2022.04.28.02.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:32:35 -0700 (PDT) Message-ID: Subject: Re: [PATCH net-next v5 08/18] net: sparx5: Replace usage of found with dedicated list iterator variable From: Paolo Abeni To: Jakob Koschel , "David S. Miller" Cc: Jakub Kicinski , 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 , Arnd Bergmann , Jason Gunthorpe , Christophe JAILLET , Colin Ian King , 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." Date: Thu, 28 Apr 2022 11:32:28 +0200 In-Reply-To: <20220427160635.420492-9-jakobkoschel@gmail.com> References: <20220427160635.420492-1-jakobkoschel@gmail.com> <20220427160635.420492-9-jakobkoschel@gmail.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, 2022-04-27 at 18:06 +0200, Jakob Koschel wrote: > 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)) { I'm sorry for the late feedback. If you move the 'mact_entry = iter;' statement here, the diffstat will be slightly smaller and the patch more readable, IMHO. There is similar situation in the next patch. Cheers, Paolo