Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4722153ioa; Wed, 27 Apr 2022 09:39:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh9TP97DvNLflJsQ/UauuFqGeDuKnEIT5BLc2PIVX5PSpjxZWKNL08oBzX8JUfj8cvEvvU X-Received: by 2002:a17:90a:e7c3:b0:1d7:4c75:3a58 with SMTP id kb3-20020a17090ae7c300b001d74c753a58mr33625784pjb.185.1651077581195; Wed, 27 Apr 2022 09:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651077581; cv=none; d=google.com; s=arc-20160816; b=P5IKx2An+a3nRwwGdYyPZQdEi2UYYaYfkTi419QWbHMk2HQtTWT3XJMcLm4SlU5HzZ jwELtQ2VidcEmKtTToa29QDRDE+zg0ZxJVjsVjB/trfSO8GqCiocqrAd7Cg+6QK0u1jU sdH9hp5ZWcDpGoEV63fSy3tSKo27uA9GSInOYn+HCpcW6Ae2ApeyIvqgoLsW6nzEEckP sv4N62fev/omFrPaUt66t6Cib/iyUALjujBoztQyHUyYEZdJQ3C61Ev6EF/3sOXkuMIW Qnbtx3B+D3sUI7ea8B6aURZLKwsk+WgDX137yLNvJxun1/BchsRtksfrP6YIUS/vSa5h Axew== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=qNVAjw1AVjFVcrN+8QdteFz8g5Tvmj9OwlQ+tinUFvQ=; b=THKVyyDDIrhW4mmAfD+hlwPJoLQA8jnk3iIaDItICL1EznvRRh4ET8Qu0nqhAZMKeX kVy9/b2wV5B/NODcVcoFlo7zYChJox70zTzD52JfvMNmAPc1bgpnkM0UEf1yukBeKu5S PZqe/Cnf4TUaCUfDQK0fVkFiwBJhidzc8Od/Z0y5G8ekR1G/Rt21fHYgD4MFvDCQk9K5 gjHt2WhVPhakAOuWMkqqF0qsBApRPR+eAf11qENqnlzk5nsaBzq3LF9duGYdupEB4Ckz yYV8VKfqN5xHL1V4DKaIsKE8OFsYzOmqfTbQ0k6KTfDh9R6RCgKdbUse2nlOn2+u6Yc+ 96bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p0CjnKts; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id p8-20020a056a000b4800b0050d3ccc654fsi2151307pfo.10.2022.04.27.09.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:39:41 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=p0CjnKts; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 B8EAC46B46B; Wed, 27 Apr 2022 09:09:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242009AbiD0QMB (ORCPT + 99 others); Wed, 27 Apr 2022 12:12:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242149AbiD0QLv (ORCPT ); Wed, 27 Apr 2022 12:11:51 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ACFA3656CA; Wed, 27 Apr 2022 09:07:43 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id j6so4310260ejc.13; Wed, 27 Apr 2022 09:07:43 -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:mime-version :content-transfer-encoding; bh=qNVAjw1AVjFVcrN+8QdteFz8g5Tvmj9OwlQ+tinUFvQ=; b=p0CjnKtsMnzlXSan+xmDjBfzonLD0gMApaxy0ct+kXepD1c+CgoWufpZ7xlPEjp13e gLcGyKMBQSBpyQPF9cxAyV98wvkH2yc5Z2e/CdRw3BEj2JTPqOmDipATYqk+hPXocdlp qUsLCSk33xqCPmgw1OG13zKZRtq65VlMmW322pA39UFYq1pD/jL3ROc68c5Ary5HCd9Y +w4TK2cP2obzOWnNfnu8mmoGnCUxjhieK5BJ9i0wyqx35enq3XkiauZmrYiRT5IjLVRT LaWuoi3W72c8fEU3gKXTbjUgp+E4eVwTMEIM/a4rqTwxFifdQEEJSYi2nq6yxX9Fbp9j 6lqA== 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:mime-version :content-transfer-encoding; bh=qNVAjw1AVjFVcrN+8QdteFz8g5Tvmj9OwlQ+tinUFvQ=; b=FB40+tn3R0+LtfSU89xmN0mRKwnGpvvTSTtYtVr3Xodvc8CBu2jkIYgSzPPKf1JK9s j7iuBNhaq6It0iIULkwyzzOCpslrwKXSD7odZnkgC64LoA7PSs7CJTUB7FbrHEcT9WxY iSc85u+ET83O3XWbJJP3WAI8E+FpDosRRNJ83+AoR6EAxj54BnnOKrBcM5wHuGe+THcI Pnz9h0R5Cgi/Mc4EhCXxKYTELHAHaCIa4EGdIxKV25O+KzmsD7RDGGKqUTZDWwamGeO5 kJ+YlmLRPCGoitCLExzZRFfatrWIMO/V1iup/qlyUpNashtqtp4/GFB7um/a8zYFUoIG HeHQ== X-Gm-Message-State: AOAM530GcY8Sgossef9wxrr6AKJV1LZDQeVTqApQaNYzH8KWPnHF9QPx hP5Lex1uLqrxhh6XatvVoK0= X-Received: by 2002:a17:907:98eb:b0:6f3:ce56:c1a2 with SMTP id ke11-20020a17090798eb00b006f3ce56c1a2mr2982061ejc.173.1651075633659; Wed, 27 Apr 2022 09:07:13 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id n5-20020a170906378500b006efb4ab6f59sm6984098ejc.86.2022.04.27.09.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:07:13 -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 , 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." Subject: [PATCH net-next v5 00/18] Remove use of list iterator after loop body Date: Wed, 27 Apr 2022 18:06:17 +0200 Message-Id: <20220427160635.420492-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 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 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 When the list iterator loop does not exit early the list iterator variable contains a type-confused pointer to a 'bogus' list element computed based on the head [1]. Often a 'found' variable is used to ensure the list iterator variable is only accessed after the loop body if the loop did exit early (using a break or goto). In other cases that list iterator variable is used in combination to access the list member which reverses the invocation of container_of() and brings back a "safe" pointer to the head of the list. Since, due to this code patten, there were quite a few bugs discovered [2], Linus concluded that the rule should be to never use the list iterator after the loop and introduce a dedicated pointer for that [3]. With the new gnu11 standard, it will now be possible to limit the scope of the list iterator variable to the traversal loop itself by defining the variable within the for loop. This, however, requires to remove all uses of the list iterator after the loop. Based on input from Paolo Abeni [4], Vinicius Costa Gomes [5], and Jakub Kicinski [6], I've splitted all the net-next related changes into two patch sets, where this is part 1.a v4->v5: - fix reverse-xmas tree in efx_alloc_rss_context_entry() (Martin Habets) v3->v4: - fix build issue in efx_alloc_rss_context_entry() (Jakub Kicinski) v2->v3: - fix commit authors and signed-off order regarding Vladimir's patches (Sorry about that, wasn't intentional.) v1->v2: - Fixed commit message for PATCH 14/18 and used dedicated variable pointing to the position (Edward Cree) - Removed redundant check in mv88e6xxx_port_vlan() (Vladimir Oltean) - Refactor mv88e6xxx_port_vlan() using separate list iterator functions (Vladimir Oltean) - Refactor sja1105_insert_gate_entry() to use separate list iterator functions (Vladimir Oltean) - Allow early return in sja1105_insert_gate_entry() if sja1105_first_entry_longer_than() didn't find any element (Vladimir Oltean) - Use list_add_tail() instead of list_add() in sja1105_insert_gate_entry() (Jakub Kicinski) - net: netcp: also use separate 'pos' variable instead of duplicating list_add() Link: https://lwn.net/Articles/887097/ [1] Link: https://lore.kernel.org/linux-kernel/20220217184829.1991035-4-jakobkoschel@gmail.com/ [2] Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [3] Link: https://lore.kernel.org/linux-kernel/7393b673c626fd75f2b4f8509faa5459254fb87c.camel@redhat.com/ [4] Link: https://lore.kernel.org/linux-kernel/877d8a3sww.fsf@intel.com/ [5] Link: https://lore.kernel.org/linux-kernel/20220403205502.1b34415d@kernel.org/ [6]