Skip to content

Commit f22b4b5

Browse files
kuba-moodavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Przemek Kitszel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6977692 commit f22b4b5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/linux/netdevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,8 @@ int call_netdevice_notifiers_info(unsigned long val,
30213021
#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
30223022

30233023
#define for_each_netdev_dump(net, d, ifindex) \
3024-
xa_for_each_start(&(net)->dev_by_index, (ifindex), (d), (ifindex))
3024+
for (; (d = xa_find(&(net)->dev_by_index, &ifindex, \
3025+
ULONG_MAX, XA_PRESENT)); ifindex++)
30253026

30263027
static inline struct net_device *next_net_device(struct net_device *dev)
30273028
{

0 commit comments

Comments
 (0)