Commit 9a810468 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

net: reduce indentation of __dev_alloc_name()



All callers of __dev_valid_name() go thru dev_prep_valid_name()
which handles the non-printf case. Focus __dev_alloc_name() on
the sprintf case, remove the indentation level.

Minor functional change of returning -EINVAL if % is not found,
which should now never happen.

Reviewed-by: default avatarJiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20231023152346.3639749-4-kuba@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 556c755a
Loading
Loading
Loading
Loading
+26 −30
Original line number Diff line number Diff line
@@ -1080,14 +1080,11 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res)
	if (!dev_valid_name(name))
		return -EINVAL;

	p = strchr(name, '%');
	if (p) {
		/*
		 * Verify the string as this thing may have come from
		 * the user.  There must be either one "%d" and no other "%"
		 * characters.
	/* Verify the string as this thing may have come from the user.
	 * There must be one "%d" and no other "%" characters.
	 */
		if (p[1] != 'd' || strchr(p + 2, '%'))
	p = strchr(name, '%');
	if (!p || p[1] != 'd' || strchr(p + 2, '%'))
		return -EINVAL;

	/* Use one page as a bit array of possible slots */
@@ -1122,7 +1119,6 @@ static int __dev_alloc_name(struct net *net, const char *name, char *res)

	i = find_first_zero_bit(inuse, max_netdevices);
	bitmap_free(inuse);
	}

	snprintf(buf, IFNAMSIZ, name, i);
	if (!netdev_name_in_use(net, buf)) {