Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp33323pxh; Thu, 7 Apr 2022 13:07:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzlqc2v0sqw/6Jx5UvQuEOCBHa9TEpzXcM5DnHbCCv3BSwJ2ZiCw1WwXWclBnpe50MY2rU X-Received: by 2002:a17:90b:4c8e:b0:1c6:8dfb:3cb6 with SMTP id my14-20020a17090b4c8e00b001c68dfb3cb6mr17881847pjb.72.1649362046480; Thu, 07 Apr 2022 13:07:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649362046; cv=none; d=google.com; s=arc-20160816; b=nEsXTKycRflnxdydEa//gJxuySQ3iA/BjMbrscJBULFFtSpwfUYARG73FDXB7R7MQP VD84dH4Xd9IlmDngvmM/JDGsbhvIbG/DtqHbvP76GdkU64W7Kfmg+8J9cQIcXwVzdpre n08j2aoWCd43nuLhuK6ULl3HyhG6hFz4wh5djqcDySuldtEHI5D+YzMvC0XPasd5TaIL ioh8XGZmqUm8auCKib02G2juxrKqtZwzuhHRM9WhVmjRMIXs3ZJqAM5V6McYQxo7pumY m2JfzvOLzY4NfzQBzx8LDoc4HpD2ewGkuYEhbwJ/jKAKOaX701Lpp8fup6bKBZ+N52j9 W4ZQ== 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=3dz7iRpPjOAQtKb60hRPumiTA9mriJZxkPOADVGQiSI=; b=tQh/EByyCo4f9M0KkH/JV7MTAfrXJbBsRbFZu3Y8OZdVve/BjtmBXdcFTDT4Ka5pE1 fY67JsXKhjhc4yXW+n4wKUgqFsHOVHUsjVHy9StBEphQpqdQCTWSJ+RY/lPHIQSFmLtE JdYkI3qODude5qiAt5orzMV/ddTbapE88pHTzuuyXY98mLEbG/cYCXmEw7Vo09aHtmbD rcXfPiUueUJkBjsby+nQHPOjsXBGd4mh+D2/NizdheJzvTbXVFLObgo0x61PTYICVQhc zQuXMyUxZUg555Vykl97MXvUnuNpqj4MWRJTFlYzLpoQt4XYyf8iIWhuVujHycAxKqvC cwPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=csVXAKM3; 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 11-20020a63174b000000b003825c501619si20247693pgx.58.2022.04.07.13.07.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:07:26 -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=csVXAKM3; 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 DC9212AC2A7; Thu, 7 Apr 2022 12:30:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244355AbiDGKe1 (ORCPT + 99 others); Thu, 7 Apr 2022 06:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244337AbiDGKdj (ORCPT ); Thu, 7 Apr 2022 06:33:39 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6915E6351; Thu, 7 Apr 2022 03:31:21 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id r10so5880930eda.1; Thu, 07 Apr 2022 03:31:21 -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=3dz7iRpPjOAQtKb60hRPumiTA9mriJZxkPOADVGQiSI=; b=csVXAKM3laW2E77iC81ROfBDCan+sJwoxRzz3uDLJ/AabmKqZa/h1OMREIPYbAy7DL YZVWZqsnEJAd2lF5Vh51rxi0XLhDHzl4IcF1325EAqlzudOqQhtWvGInS45hyN46ODYI SMTfSHnCUFxW9DbJu/NTmDfHChOPiKDzbnKLESwBTQvPcRpgkwP+k3ugkjIYb+AjYHLg snQJh9ee6kjEL6c024zYAgMmk0gnDJQij7zVBaIukop0fTcIuQLmgkTK1TT+WCuuurnk S+nmEdW5d35uNuwN0F/7oEz9/VROBtIeFYq8DAlzGrNuL7BvsB6dys36x2tYbGPl5oUF 0Nlw== 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=3dz7iRpPjOAQtKb60hRPumiTA9mriJZxkPOADVGQiSI=; b=52lsgc7xOxQwgh3J91UpVNpWUkAZQi1AoK3uKcnsGsVLGTs+2Kej7XCCINgB7LnD4r Ju2SMamEMnFpeXAaiXhQQfRu80y2xqFLO9NOYKbDjuT2w3y6baZd7XRv9x1tiwd6M55w xQdCpMesSQyOqM5aSNU/swvq621EpJ4K5kFDwPJzSmSuU06YRe3Iuo+Thw/WIdqwe0ap uHgxNAV/Jh5ZNj0u5BeiQpyR9u3QsdB4b42xxjFS/pgrA7p8FpAEdz3LcuxHQeKiYkpU 0kYQkIg0YWESZVEiVPMe67bU4smx4AxBIftr+bobVLS74VN/+Jdyo3bsrvPRI7Un13yV TPug== X-Gm-Message-State: AOAM533Im28QruiMwtM45Wxg+xESjxibh0BwVFq60q2/vtPlWi8Ez+uV lYiv14e5qLhjPAhscubavAc= X-Received: by 2002:aa7:dd9a:0:b0:41d:d67:3c10 with SMTP id g26-20020aa7dd9a000000b0041d0d673c10mr1172068edv.363.1649327479846; Thu, 07 Apr 2022 03:31:19 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id c5-20020a170906d18500b006ce371f09d4sm7413573ejz.57.2022.04.07.03.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 03:31:19 -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 , Casper Andersson , Bjarni Jonasson , Jakob Koschel , Colin Ian King , Michael Walle , Christophe JAILLET , Arnd Bergmann , Eric Dumazet , Di Zhu , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH net-next 15/15] team: Remove use of list iterator variable for list_for_each_entry_from() Date: Thu, 7 Apr 2022 12:29:00 +0200 Message-Id: <20220407102900.3086255-16-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220407102900.3086255-1-jakobkoschel@gmail.com> References: <20220407102900.3086255-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 In preparation to limit the scope of the list iterator variable to the list traversal loop, use a dedicated pointer to iterate through the list [1]. Since that variable should not be used past the loop iteration, a separate variable is used to 'remember the current location within the loop'. By avoiding the use of the iterator variable after the loop, we can lower the scope of it to the list traversal macros in the future. To either continue iterating from that position or skip the iteration (if the previous iteration was complete) list_prepare_entry() is used. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel --- drivers/net/team/team.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index b07dde6f0abf..688c4393f099 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -2425,17 +2425,17 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, int flags, team_nl_send_func_t *send_func, struct list_head *sel_opt_inst_list) { + struct team_option_inst *opt_inst, *tmp = NULL; struct nlattr *option_list; struct nlmsghdr *nlh; void *hdr; - struct team_option_inst *opt_inst; int err; struct sk_buff *skb = NULL; bool incomplete; int i; - opt_inst = list_first_entry(sel_opt_inst_list, - struct team_option_inst, tmp_list); + tmp = list_first_entry(sel_opt_inst_list, + struct team_option_inst, tmp_list); start_again: err = __send_and_alloc_skb(&skb, team, portid, send_func); @@ -2456,7 +2456,9 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, goto nla_put_failure; i = 0; + opt_inst = list_prepare_entry(tmp, sel_opt_inst_list, tmp_list); incomplete = false; + tmp = NULL; list_for_each_entry_from(opt_inst, sel_opt_inst_list, tmp_list) { err = team_nl_fill_one_option_get(skb, team, opt_inst); if (err) { @@ -2464,6 +2466,7 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, if (!i) goto errout; incomplete = true; + tmp = opt_inst; break; } goto errout; @@ -2707,14 +2710,14 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, struct nlattr *port_list; struct nlmsghdr *nlh; void *hdr; - struct team_port *port; + struct team_port *port, *tmp = NULL; int err; struct sk_buff *skb = NULL; bool incomplete; int i; - port = list_first_entry_or_null(&team->port_list, - struct team_port, list); + tmp = list_first_entry_or_null(&team->port_list, + struct team_port, list); start_again: err = __send_and_alloc_skb(&skb, team, portid, send_func); @@ -2744,7 +2747,9 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, err = team_nl_fill_one_port_get(skb, one_port); if (err) goto errout; - } else if (port) { + } else { + port = list_prepare_entry(tmp, &team->port_list, list); + tmp = NULL; list_for_each_entry_from(port, &team->port_list, list) { err = team_nl_fill_one_port_get(skb, port); if (err) { @@ -2752,6 +2757,7 @@ static int team_nl_send_port_list_get(struct team *team, u32 portid, u32 seq, if (!i) goto errout; incomplete = true; + tmp = port; break; } goto errout; -- 2.25.1