linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 00/18] Remove use of list iterator after loop body
@ 2022-04-12 10:58 Jakob Koschel
  2022-04-12 10:58 ` [PATCH net-next v2 01/18] connector: Replace usage of found with dedicated list iterator variable Jakob Koschel
                   ` (17 more replies)
  0 siblings, 18 replies; 22+ messages in thread
From: Jakob Koschel @ 2022-04-12 10:58 UTC (permalink / raw)
  To: David S. Miller
  Cc: Andrew Lunn, Song Liu, Alexei Starovoitov, Eric Dumazet,
	Paul Mackerras, Ariel Elior, Florian Fainelli, Daniel Borkmann,
	Steen Hegelund, John Fastabend, Andrii Nakryiko, Bos, H.J.,
	linux-arm-kernel, Martin Habets, Paolo Abeni, Vivien Didelot,
	Jiri Pirko, Arnd Bergmann, KP Singh, Christophe JAILLET,
	Jakob Koschel, Jakub Kicinski, Brian Johannesmeyer, Lars Povlsen,
	Colin Ian King, Manish Chopra, netdev, linux-kernel,
	UNGLinuxDriver, Yonghong Song, Edward Cree, Michael Walle,
	Casper Andersson, Xu Wang, Cristiano Giuffrida, bpf,
	Vladimir Oltean, linuxppc-dev, Martin KaFai Lau, Mike Rapoport

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


^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-04-12 12:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-12 10:58 [PATCH net-next v2 00/18] Remove use of list iterator after loop body Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 01/18] connector: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 02/18] net: dsa: sja1105: remove use of iterator after list_for_each_entry() loop Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 03/18] net: dsa: sja1105: reorder sja1105_first_entry_longer_than with memory allocation Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 04/18] net: dsa: sja1105: use list_add_tail(pos) instead of list_add(pos->prev) Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 05/18] net: dsa: mv88e6xxx: remove redundant check in mv88e6xxx_port_vlan() Jakob Koschel
2022-04-12 11:27   ` Russell King (Oracle)
2022-04-12 11:37     ` Jakob Koschel
2022-04-12 12:56       ` Paolo Abeni
2022-04-12 10:58 ` [PATCH net-next v2 06/18] net: dsa: mv88e6xxx: refactor mv88e6xxx_port_vlan() Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 07/18] net: dsa: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 08/18] net: sparx5: " Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 09/18] qed: Use " Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 10/18] qed: Replace usage of found with " Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 11/18] qed: Remove usage of list iterator variable after the loop Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 12/18] net: qede: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 13/18] net: qede: Remove check of list iterator against head past the loop body Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 14/18] sfc: Remove usage of list iterator for list_add() after " Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 15/18] net: netcp: Remove usage of list iterator for list_add() after " Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 16/18] ps3_gelic: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 17/18] ipvlan: Remove usage of list iterator variable for the loop body Jakob Koschel
2022-04-12 10:58 ` [PATCH net-next v2 18/18] team: Remove use of list iterator variable for list_for_each_entry_from() Jakob Koschel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).