[BRIDGE]: fix locking and memory leak in br_add_bridge

There are several bugs in error handling in br_add_bridge:
- when dev_alloc_name fails, allocated net_device is not freed
- unregister_netdev is called when rtnl lock is held
- free_netdev is called before netdev_run_todo has a chance to be run after
  unregistering net_device

Signed-off-by: Jiri Benc <jbenc@suse.cz>
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jiri Benc 2006-06-05 16:39:34 -07:00 committed by David S. Miller
parent 8c893ff6ab
commit 36485707bb

View File

@ -300,25 +300,20 @@ int br_add_bridge(const char *name)
rtnl_lock(); rtnl_lock();
if (strchr(dev->name, '%')) { if (strchr(dev->name, '%')) {
ret = dev_alloc_name(dev, dev->name); ret = dev_alloc_name(dev, dev->name);
if (ret < 0) if (ret < 0) {
goto err1; free_netdev(dev);
goto out;
}
} }
ret = register_netdevice(dev); ret = register_netdevice(dev);
if (ret) if (ret)
goto err2; goto out;
ret = br_sysfs_addbr(dev); ret = br_sysfs_addbr(dev);
if (ret) if (ret)
goto err3; unregister_netdevice(dev);
rtnl_unlock(); out:
return 0;
err3:
unregister_netdev(dev);
err2:
free_netdev(dev);
err1:
rtnl_unlock(); rtnl_unlock();
return ret; return ret;
} }