From 9e2e61fbf8ad016d24e4af0afff13505f3dd2a2a Mon Sep 17 00:00:00 2001 From: Amerigo Wang Date: Wed, 31 Mar 2010 21:30:52 +0000 Subject: [PATCH] bonding: fix potential deadlock in bond_uninit() bond_uninit() is invoked with rtnl_lock held, when it does destroy_workqueue() which will potentially flush all works in this workqueue, if we hold rtnl_lock again in the work function, it will deadlock. So move destroy_workqueue() to destructor where rtnl_lock is not held any more, suggested by Eric. Signed-off-by: WANG Cong Cc: Jay Vosburgh Cc: "David S. Miller" Cc: Stephen Hemminger Cc: Jiri Pirko Cc: "Eric W. Biederman" Signed-off-by: David S. Miller --- drivers/net/bonding/bond_main.c | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-) Index: linux-2.6.32-SLE11-SP1/drivers/net/bonding/bond_main.c =================================================================== --- linux-2.6.32-SLE11-SP1.orig/drivers/net/bonding/bond_main.c +++ linux-2.6.32-SLE11-SP1/drivers/net/bonding/bond_main.c @@ -1975,9 +1975,6 @@ static void bond_uninit(struct net_devic bond_deinit(bond_dev); bond_destroy_sysfs_entry(bond); - if (bond->wq) - destroy_workqueue(bond->wq); - netif_addr_lock_bh(bond_dev); bond_mc_list_destroy(bond); netif_addr_unlock_bh(bond_dev); @@ -4501,6 +4498,14 @@ static const struct net_device_ops bond_ .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid, }; +static void bond_destructor(struct net_device *bond_dev) +{ + struct bonding *bond = netdev_priv(bond_dev); + if (bond->wq) + destroy_workqueue(bond->wq); + free_netdev(bond_dev); +} + static void bond_setup(struct net_device *bond_dev) { struct bonding *bond = netdev_priv(bond_dev); @@ -4521,7 +4526,7 @@ static void bond_setup(struct net_device bond_dev->ethtool_ops = &bond_ethtool_ops; bond_set_mode_ops(bond, bond->params.mode); - bond_dev->destructor = free_netdev; + bond_dev->destructor = bond_destructor; /* Initialize the device options */ bond_dev->tx_queue_len = 0; @@ -5054,14 +5059,14 @@ int bond_create(const char *name) if (!bond_dev) { pr_err(DRV_NAME ": %s: eek! can't alloc netdev!\n", name); - res = -ENOMEM; - goto out_rtnl; + rtnl_unlock(); + return -ENOMEM; } if (!name) { res = dev_alloc_name(bond_dev, "bond%d"); if (res < 0) - goto out_netdev; + goto out_bond; } res = register_netdevice(bond_dev); @@ -5079,10 +5084,9 @@ out_unreg: unregister_netdevice(bond_dev); out_bond: bond_deinit(bond_dev); -out_netdev: - free_netdev(bond_dev); out_rtnl: rtnl_unlock(); + bond_destructor(bond_dev); return res; }