Skip to content

Commit

Permalink
net: set name assign type for renamed devices
Browse files Browse the repository at this point in the history
Based on a patch from David Herrmann.

This is the only place devices can be renamed.

v9: restore revers-christmas-tree order of local variables

Signed-off-by: Tom Gundersen <[email protected]>
Reviewed-by: David Herrmann <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
teg authored and davem330 committed Jul 15, 2014
1 parent 685343f commit 238fa36
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ static int dev_get_valid_name(struct net *net,
*/
int dev_change_name(struct net_device *dev, const char *newname)
{
unsigned char old_assign_type;
char oldname[IFNAMSIZ];
int err = 0;
int ret;
Expand Down Expand Up @@ -1109,10 +1110,14 @@ int dev_change_name(struct net_device *dev, const char *newname)
return err;
}

old_assign_type = dev->name_assign_type;
dev->name_assign_type = NET_NAME_RENAMED;

rollback:
ret = device_rename(&dev->dev, dev->name);
if (ret) {
memcpy(dev->name, oldname, IFNAMSIZ);
dev->name_assign_type = old_assign_type;
write_seqcount_end(&devnet_rename_seq);
return ret;
}
Expand Down Expand Up @@ -1141,6 +1146,8 @@ int dev_change_name(struct net_device *dev, const char *newname)
write_seqcount_begin(&devnet_rename_seq);
memcpy(dev->name, oldname, IFNAMSIZ);
memcpy(oldname, newname, IFNAMSIZ);
dev->name_assign_type = old_assign_type;
old_assign_type = NET_NAME_RENAMED;
goto rollback;
} else {
pr_err("%s: name change rollback failed: %d\n",
Expand Down

0 comments on commit 238fa36

Please sign in to comment.