Subject: Re: [PATCH] net: check all name nodes in __dev_alloc_name

From: Stephen Hemminger <[email-masked]>
Date: Wed, 17 Mar 2021 21:11:08 -0700

On Thu, 18 Mar 2021 04:42:53 +0100
Jiri Bohac <[email-masked]> wrote:

>  		for_each_netdev(net, d) {
> +			struct netdev_name_node *name_node;
> +			list_for_each_entry(name_node, &d->name_node->list, list) {
> +				if (!sscanf(name_node->name, name, &i))
> +					continue;
> +				if (i < 0 || i >= max_netdevices)
> +					continue;
> +
> +				/*  avoid cases where sscanf is not exact inverse of printf */
> +				snprintf(buf, IFNAMSIZ, name, i);
> +				if (!strncmp(buf, name_node->name, IFNAMSIZ))
> +					set_bit(i, inuse);
> +			}

Rather than copy/paste same code two places, why not make a helper function?