]> www.infradead.org Git - users/willy/linux.git/commit
net: make for_each_netdev_dump() a little more bug-proof
authorJakub Kicinski <kuba@kernel.org>
Thu, 13 Jun 2024 21:33:16 +0000 (14:33 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 Jun 2024 12:11:02 +0000 (13:11 +0100)
commitf22b4b55edb507a2b30981e133b66b642be4d13f
treec9ced0c69737abdd6713f376e00d499acbb691f3
parent69776921e82d48a165a37438f48c46edf0456275
net: make for_each_netdev_dump() a little more bug-proof

I find the behavior of xa_for_each_start() slightly counter-intuitive.
It doesn't end the iteration by making the index point after the last
element. IOW calling xa_for_each_start() again after it "finished"
will run the body of the loop for the last valid element, instead
of doing nothing.

This works fine for netlink dumps if they terminate correctly
(i.e. coalesce or carefully handle NLM_DONE), but as we keep getting
reminded legacy dumps are unlikely to go away.

Fixing this generically at the xa_for_each_start() level seems hard -
there is no index reserved for "end of iteration".
ifindexes are 31b wide, tho, and iterator is ulong so for
for_each_netdev_dump() it's safe to go to the next element.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h