Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp792276pxb; Tue, 12 Apr 2022 13:35:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuE+x/HlATB4Y+D2vLf5WvBQjHR8o1IdDCcPTfjK6i4BQCgiAjli3FsG5yMr9q8GYspTdT X-Received: by 2002:a17:90b:1a85:b0:1c9:d81b:33f1 with SMTP id ng5-20020a17090b1a8500b001c9d81b33f1mr6958198pjb.212.1649795715425; Tue, 12 Apr 2022 13:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649795715; cv=none; d=google.com; s=arc-20160816; b=vk4ogNklY76KFrBhOo5RmH3vu/eQ7MwR22eMumH0kt7zHTz49dVEiw7a2YT1A3yUt3 g3VDuHqH6t7ut9oo4pmpYRp5GlopdAAcQ8laCg/URqz17kwR/ZTXLeebmS4Xjv4y1n0x cN5CL4l2V82B/Maw7i8iEkyXiDLi6TVw0jGw0CIV1R4hXPTXC37/EqtzRL6NsRxMQ1GK 0BW0gaH8hhSB8/xivG2Vpad6YDch2rQ6q+jp8p1xtH156jhyKvQNi5tkMWcCO9eVMPWn 73ZjGA/9+7CdwkO4DcNiDgDn0hrrcD3KB0/1pORVcSLR/xgXiFHn4XDwfLP6FMQULVFu fbww== 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=+eJGktqK5V7HDq2U3VQXwapNjHNoENEgBXt1QNATELQ=; b=uYs/rB7FNa4qwtWscem5SSeyw++flisSYzW8414Sn13ZMrv/e/GPsZFJIhesu07vey 7ks/UE3Rg7+/zX7g+hUjn+sQ0qT4zspFMbwT/Mp5562k4VlCT46vgqv4kgBRgY36qGdO /cwNDwwTlbFnpZ3JUW6GPsCq5WADMrge9rqMk2/IviSeoPIgxKV6teyy9tw+Zg9XEgxJ WtZFuxFREKhNULOIPUu1w3aC6wNrDL+TzySDUV/2f4UyV0ZWp7OLB54S2nH5X12Hl/Q7 NKBl9zkId3xhkwRIwcnfwP/tJf55YXN8NSPxPeMCyoBabr51xJjiWMpsHngEmjIagyW7 NqbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZoFzb3tl; 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 n10-20020a170902d2ca00b00153b2d16431si14068510plc.57.2022.04.12.13.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:35:15 -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=ZoFzb3tl; 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 D8F3A72E1C; Tue, 12 Apr 2022 13:09:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239590AbiDLME6 (ORCPT + 99 others); Tue, 12 Apr 2022 08:04:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351243AbiDLMCg (ORCPT ); Tue, 12 Apr 2022 08:02:36 -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 0D20C76595; Tue, 12 Apr 2022 03:58:53 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id bg10so36566167ejb.4; Tue, 12 Apr 2022 03:58:52 -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=+eJGktqK5V7HDq2U3VQXwapNjHNoENEgBXt1QNATELQ=; b=ZoFzb3tloXo+McRmkV6Gjg4GWW6lT27yGVpQhLtkyv6VtKJAkz3EOXC4aqUvcXQxTA fZk3vQyLWDrVKZghgFc8vooDWaYuBRlPXfhKU+uU/xhrw6hd7uU4BFjbWhlzkFjAmGPZ AIZAfM2nYSXw9Ziw9eywORZ+2hSZYIx9hW/8V3WAYu6elqDnzP3N5e2LzkpnKJ43TMAg iLr3BrXHMV+92mMcEL6FrJKEr+fP3v1xYy4dAD5BLkMFLvOjt24AkA2BpkvT1SFiy4I5 OnZ9KtzFh9kv4tfn0kHZtUOosQl6A6yWQT8ZQdfvLARlvhWkUPNuOfcm+A8pYz1USsFA K9dA== 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=+eJGktqK5V7HDq2U3VQXwapNjHNoENEgBXt1QNATELQ=; b=HMopq+KcYuG1ZW1IisA9oALTsc3/VcHlfzlq+0hZeFOCYfuO379WjlwsUemsE63Cos MTYUNOVx6byXWjOz/Tge4TvBuY95G8b0191x5eTq5lylheH/JT9OS73rRVc6O2I03JBQ e1tFfmHi/XW8qkRgRTw+9y0Y8bi5rqRX+61MslrPmK9NuescZjISUKDQZP/s59vBtHAi EjpOS2Dx8yUAhVoEV5CHWBVUmucAgHNiqXBFV7x8ewCfTmdDWi54Ymm6FYRp74aoQAQU W0Jb+Sipvorb7hzQx8ZKOravOUBmx6s5/WLYbd+kzJhZMe27TS+eD/CFCZkQCwFtvM9d B7WQ== X-Gm-Message-State: AOAM530T+L/eNdT5RVPQjLsa+io+2t9EbIi9HZIln5YyLnfZJe81tHbj ykjOm9UwoJoZv0q1n25i72HOd05fRggIlQ== X-Received: by 2002:a17:906:1603:b0:6ce:362:c938 with SMTP id m3-20020a170906160300b006ce0362c938mr34467412ejd.253.1649761131410; Tue, 12 Apr 2022 03:58:51 -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.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 03:58:50 -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 00/18] Remove use of list iterator after loop body Date: Tue, 12 Apr 2022 12:58:12 +0200 Message-Id: <20220412105830.3495846-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. 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] Jakob Koschel (18): connector: Replace usage of found with dedicated list iterator variable net: dsa: sja1105: remove use of iterator after list_for_each_entry() loop net: dsa: sja1105: reorder sja1105_first_entry_longer_than with memory allocation net: dsa: sja1105: use list_add_tail(pos) instead of list_add(pos->prev) net: dsa: mv88e6xxx: remove redundant check in mv88e6xxx_port_vlan() net: dsa: mv88e6xxx: refactor mv88e6xxx_port_vlan() net: dsa: Replace usage of found with dedicated list iterator variable net: sparx5: Replace usage of found with dedicated list iterator variable qed: Use dedicated list iterator variable qed: Replace usage of found with dedicated list iterator variable qed: Remove usage of list iterator variable after the loop net: qede: Replace usage of found with dedicated list iterator variable net: qede: Remove check of list iterator against head past the loop body sfc: Remove usage of list iterator for list_add() after the loop body net: netcp: Remove usage of list iterator for list_add() after loop body ps3_gelic: Replace usage of found with dedicated list iterator variable ipvlan: Remove usage of list iterator variable for the loop body team: Remove use of list iterator variable for list_for_each_entry_from() drivers/connector/cn_queue.c | 13 ++--- drivers/net/dsa/mv88e6xxx/chip.c | 57 ++++++++++--------- drivers/net/dsa/sja1105/sja1105_vl.c | 51 +++++++++-------- .../microchip/sparx5/sparx5_mactable.c | 25 ++++---- drivers/net/ethernet/qlogic/qed/qed_dev.c | 11 ++-- drivers/net/ethernet/qlogic/qed/qed_iwarp.c | 26 ++++----- drivers/net/ethernet/qlogic/qed/qed_spq.c | 6 +- .../net/ethernet/qlogic/qede/qede_filter.c | 11 ++-- drivers/net/ethernet/qlogic/qede/qede_rdma.c | 11 ++-- drivers/net/ethernet/sfc/rx_common.c | 8 ++- drivers/net/ethernet/ti/netcp_core.c | 14 +++-- .../net/ethernet/toshiba/ps3_gelic_wireless.c | 30 +++++----- drivers/net/ipvlan/ipvlan_main.c | 7 ++- drivers/net/team/team.c | 20 ++++--- net/dsa/dsa.c | 11 ++-- 15 files changed, 163 insertions(+), 138 deletions(-) base-commit: 3e732ebf7316ac83e8562db7e64cc68aec390a18 -- 2.25.1