Skip to content

Commit

Permalink
net: core: dev_get_valid_name is now the same as dev_alloc_name_ns
Browse files Browse the repository at this point in the history
If name contains a %, it's easy to see that this patch doesn't change
anything (other than eliminate the duplicate dev_valid_name
call). Otherwise, we'll now just spend a little time in snprintf()
copying name to the stack buffer allocated in dev_alloc_name_ns, and do
the __dev_get_by_name using that buffer rather than name.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Rasmus Villemoes authored and David S. Miller committed Nov 14, 2017
1 parent d6f295e commit 87c320e
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,19 +1146,7 @@ EXPORT_SYMBOL(dev_alloc_name);
int dev_get_valid_name(struct net *net, struct net_device *dev,
const char *name)
{
BUG_ON(!net);

if (!dev_valid_name(name))
return -EINVAL;

if (strchr(name, '%'))
return dev_alloc_name_ns(net, dev, name);
else if (__dev_get_by_name(net, name))
return -EEXIST;
else if (dev->name != name)
strlcpy(dev->name, name, IFNAMSIZ);

return 0;
return dev_alloc_name_ns(net, dev, name);
}
EXPORT_SYMBOL(dev_get_valid_name);

Expand Down

0 comments on commit 87c320e

Please sign in to comment.