Skip to content

Commit

Permalink
net: correct error path in rtnl_newlink()
Browse files Browse the repository at this point in the history
I saw the following BUG when ->newlink() fails in rtnl_newlink():

[   40.240058] kernel BUG at net/core/dev.c:6438!

this is due to free_netdev() is not supposed to be called before
netdev is completely unregistered, therefore it is not correct
to call free_netdev() here, at least for ops->newlink!=NULL case,
many drivers call it in ->destructor so that rtnl_unlock() will
take care of it, we probably don't need to do anything here.

Cc: David S. Miller <[email protected]>
Cc: Eric Dumazet <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang1986 authored and davem330 committed Feb 13, 2014
1 parent da37705 commit 0e0eee2
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,16 +1963,21 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)

dev->ifindex = ifm->ifi_index;

if (ops->newlink)
if (ops->newlink) {
err = ops->newlink(net, dev, tb, data);
else
/* Drivers should call free_netdev() in ->destructor
* and unregister it on failure so that device could be
* finally freed in rtnl_unlock.
*/
if (err < 0)
goto out;
} else {
err = register_netdevice(dev);

if (err < 0) {
free_netdev(dev);
goto out;
if (err < 0) {
free_netdev(dev);
goto out;
}
}

err = rtnl_configure_link(dev, ifm);
if (err < 0)
unregister_netdevice(dev);
Expand Down

0 comments on commit 0e0eee2

Please sign in to comment.