Subject: Re: [PATCH net-next 2/2] rtnetlink: use xarray iterator to implement rtnl_dump_ifinfo()

From: Jakub Kicinski <[email-masked]>
Date: Fri, 9 Feb 2024 14:24:41 -0800

On Fri,  9 Feb 2024 14:56:15 +0000 Eric Dumazet wrote:
> +	unsigned long ifindex = cb->args[0];

[snip]

> +	for_each_netdev_dump(tgt_net, dev, ifindex) {
> +		if (link_dump_filtered(dev, master_idx, kind_ops))
> +			continue;
> +		err = rtnl_fill_ifinfo(skb, dev, net, RTM_NEWLINK,
> +				       NETLINK_CB(cb->skb).portid,
> +				       nlh->nlmsg_seq, 0, flags,
> +				       ext_filter_mask, 0, NULL, 0,
> +				       netnsid, GFP_KERNEL);
> +
> +		if (err < 0)
> +			break;
> +		cb->args[0] = ifindex + 1;

Perhaps we can cast the context buffer onto something typed and use 
it directly? I think it's a tiny bit less error prone:

	struct {
		unsigned long ifindex;
	} *ctx = (void *)cb->ctx;

Then we can:

	for_each_netdev_dump(tgt_net, dev, ctx->ifindex)
					   ^^^^^^^^^^^^

and not need to worry about saving the ifindex back to cb before
exiting.

Up to you.