Skip to content

Commit

Permalink
[BRIDGE]: fix locking and memory leak in br_add_bridge
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Stephen Hemminger <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jiri Benc authored and davem330 committed Jun 5, 2006
1 parent 8c893ff commit 3648570
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions net/bridge/br_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,20 @@ int br_add_bridge(const char *name)
rtnl_lock();
if (strchr(dev->name, '%')) {
ret = dev_alloc_name(dev, dev->name);
if (ret < 0)
goto err1;
if (ret < 0) {
free_netdev(dev);
goto out;
}
}

ret = register_netdevice(dev);
if (ret)
goto err2;
goto out;

ret = br_sysfs_addbr(dev);
if (ret)
goto err3;
rtnl_unlock();
return 0;

err3:
unregister_netdev(dev);
err2:
free_netdev(dev);
err1:
unregister_netdevice(dev);
out:
rtnl_unlock();
return ret;
}
Expand Down

0 comments on commit 3648570

Please sign in to comment.