Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp980675pxb; Fri, 15 Apr 2022 17:17:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMvcobZePJPLndoZo2pcqG5uW03wukeqZ1AKkFzS24z1e9yzAw/PlvBaxT24A67yZ8IE7y X-Received: by 2002:a17:90b:1c8f:b0:1b8:c6dc:ca61 with SMTP id oo15-20020a17090b1c8f00b001b8c6dcca61mr1418096pjb.13.1650068270169; Fri, 15 Apr 2022 17:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650068270; cv=none; d=google.com; s=arc-20160816; b=Elg1PS4KT2lSUlw1S+xX1G5+CUWu47cyExiNJ0gNHu6iZ8k1CAYBIPXbHFwj2zBUY/ Iai3rEhtdy2KYuaYtgXiMJnksmKKtf2J0sIAqKa9Q/DAxpzgjDOcg72TKeRVJA+mDwSl 6/wLQG4hfqk2QkLCfY+ved1jT5rW2lYcFNBRryDK07QOun6Otmj+VlZ5FDo1dCv58wZn dEpALRD8cG/lIKuFmBtlvuJhZsfNbg2OFb7akDMu+0w+7KC4sMilh0Groh6iiFMGXO+K RlRgumpmFygcw3eFzel62sAxrmEFgfl9NPeixfLvwUhyUPuW3EIH+WcrNRtQkW+teEtt L33g== 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=+lM1IKIROI0118a8QEjx+0FHb0+kDze7UWxx8pEgal0=; b=yabjuQw3vexPzruGVkB3NuWryZG3vNMVjeJtowJEYPuE4zqh6wRvrvtEo1W9iFlCrO khw8D5G0to6P1XbC4YylCiU+LeXxQrUIlB6gXe9mQn8Rn9ws2kyigwdCN6vIYsLz43s3 1BnU92IjJMJpZmfTQVFFOYl95hjctpFLBNRYN+tG88a7fvyb6iSGdr/JZNks88aWmu77 kDn+QIxG4HXDxSwUfsWkcIzFN/wU2DLZl7by7Ba11PS4NWI893/TbnMOAPyZJxQaLsfa zE097LVR1LHOSZUz8fC03rNgsS7kVHbm+Si1NR8QQvDgIFMAP/EttKbI1YOCxO9tDkB+ vQ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RzDuK9kt; 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 f19-20020a631013000000b00398ebebcaa8si2789596pgl.261.2022.04.15.17.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 17:17:50 -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=RzDuK9kt; 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 2EF99CFBBD; Fri, 15 Apr 2022 17:17:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343684AbiDOMeP (ORCPT + 99 others); Fri, 15 Apr 2022 08:34:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353799AbiDOMdO (ORCPT ); Fri, 15 Apr 2022 08:33:14 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E116D329A7; Fri, 15 Apr 2022 05:30:45 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id t11so15100979eju.13; Fri, 15 Apr 2022 05:30:45 -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=+lM1IKIROI0118a8QEjx+0FHb0+kDze7UWxx8pEgal0=; b=RzDuK9ktprDk3VXuKJF6rwgVi6LlAURN3/cppgJyIK2bZHawZScqp2vgmeE1kU8xia mkvAAQXXSUMQNfcARoGLZDPoE0xY9A6ivmUIZbTFx+pBqHz3AJh8XUFNrEn+uraBXtuO FESiDtJ94rtYc67Xaf/S80W1CEd84L1UhNCLcEH09Z3gcZj5uepMlIK+GBbQfj13EQii BLRGOZ64yi2hoMSX593Z4YN0LWe7dX22mgVbgz+LWosxqfSV7QXXFGsGJNOYLdOIVCXf KAkH/VyqDKOlw3jqUfi156ha9gIC8nYUBxBOzU7qc2/dvdmnZYhSdlBv+WPDID6irS+Y 4BtA== 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=+lM1IKIROI0118a8QEjx+0FHb0+kDze7UWxx8pEgal0=; b=aiZovmd+x6UU+R08upfLHIm3cifoSZQpcAQBxLlo/eKPI3ifL2XNSIiwBaWURjryzg 5fNvnV/zYJI91psQihF66hPod8SztPh57xjPcWo3mNMryU/aXgXrz4zW06nWSUuy18hI PQQTl9wf316Sq7Tck1/6pAt+mQp4H+XJ9yVRHPIKPR+H+tR/l3aStmbPuKgEFef/vehr L0NWh7MBBGlbpALl1TW6b5VPpk8CB2w/+muFCJr+j78meTkBI6N5vrn1wVjXDeoSA130 ceuDhEs+bDfShJ3Dx5dPQTeUeug3cR6MGpWm8t+DpI62GHzGxvrvsSZKlMIuMdKO3nE7 X4Ig== X-Gm-Message-State: AOAM532j8twE845YxTIKwcZOa0VtPxr4T1F8++xeCrJT7sxm+Z4r7By1 eLW3vQop3zzDrWMW1NW/02w= X-Received: by 2002:a17:907:629a:b0:6d7:b33e:43f4 with SMTP id nd26-20020a170907629a00b006d7b33e43f4mr6238897ejc.149.1650025844417; Fri, 15 Apr 2022 05:30:44 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id bo14-20020a170906d04e00b006ce98d9c3e3sm1649533ejb.194.2022.04.15.05.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 05:30:43 -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 , Bjarni Jonasson , Jakob Koschel , Christophe JAILLET , Arnd Bergmann , 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 v4 00/18] Remove use of list iterator after loop body Date: Fri, 15 Apr 2022 14:29:29 +0200 Message-Id: <20220415122947.2754662-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,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 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. 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]