提交 0e0eee24 编写于 作者: C Cong Wang 提交者: 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: NCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: NCong Wang <cwang@twopensource.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册