linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 00/15] net: Remove use of list iterator after loop body
@ 2022-04-07 10:28 Jakob Koschel
  2022-04-07 10:28 ` [PATCH net-next 01/15] connector: Replace usage of found with dedicated list iterator variable Jakob Koschel
                   ` (14 more replies)
  0 siblings, 15 replies; 37+ messages in thread
From: Jakob Koschel @ 2022-04-07 10:28 UTC (permalink / raw)
  To: David S. Miller
  Cc: Jakub Kicinski, Paolo Abeni, Andrew Lunn, Vivien Didelot,
	Florian Fainelli, Vladimir Oltean, Lars Povlsen, Steen Hegelund,
	UNGLinuxDriver, 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,
	linux-kernel, linux-arm-kernel, linuxppc-dev, Mike Rapoport,
	Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.

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.

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]


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

end of thread, other threads:[~2022-04-10 20:35 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 10:28 [PATCH net-next 00/15] net: Remove use of list iterator after loop body Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 01/15] connector: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of iterator for list_add() after loop Jakob Koschel
2022-04-08  3:54   ` Jakub Kicinski
2022-04-08 23:58     ` Jakob Koschel
2022-04-09  0:04       ` Jakub Kicinski
2022-04-09  0:08       ` Vladimir Oltean
2022-04-08  7:47   ` Christophe Leroy
2022-04-08 23:49     ` Jakob Koschel
2022-04-08 11:41   ` Vladimir Oltean
2022-04-08 23:54     ` Jakob Koschel
2022-04-10 10:51       ` Jakob Koschel
2022-04-10 11:05         ` Vladimir Oltean
2022-04-10 12:39           ` Jakob Koschel
2022-04-10 18:24             ` Jakob Koschel
2022-04-10 20:02               ` Vladimir Oltean
2022-04-10 20:30                 ` Jakob Koschel
2022-04-10 20:34                   ` Vladimir Oltean
2022-04-07 10:28 ` [PATCH net-next 03/15] net: dsa: mv88e6xxx: Replace usage of found with dedicated iterator Jakob Koschel
2022-04-08 12:31   ` Vladimir Oltean
2022-04-08 23:44     ` Jakob Koschel
2022-04-08 23:50       ` Vladimir Oltean
2022-04-09  0:00         ` Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 04/15] net: dsa: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 05/15] net: sparx5: " Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 06/15] qed: Use " Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 07/15] qed: Replace usage of found with " Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 08/15] qed: Remove usage of list iterator variable after the loop Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 09/15] net: qede: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 10/15] net: qede: Remove check of list iterator against head past the loop body Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 11/15] sfc: Remove usage of list iterator for list_add() after " Jakob Koschel
2022-04-07 17:42   ` Edward Cree
2022-04-09  0:10     ` Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 12/15] net: netcp: Remove usage of list iterator for list_add() after " Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 13/15] ps3_gelic: Replace usage of found with dedicated list iterator variable Jakob Koschel
2022-04-07 10:28 ` [PATCH net-next 14/15] ipvlan: Remove usage of list iterator variable for the loop body Jakob Koschel
2022-04-07 10:29 ` [PATCH net-next 15/15] 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).