Commit 0e0eee24 authored by Cong Wang's avatar Cong Wang Committed by David S. Miller

net: correct error path in rtnl_newlink()

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 <davem@davemloft.net>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarCong Wang <cwang@twopensource.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent da37705c
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment