diff options
author | Hugh Daschbach <hdasch@broadcom.com> | 2010-03-22 13:36:37 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-05-21 12:37:30 -0400 |
commit | 6245838fe4d2ce4aab52f543224f7d1212d9155c (patch) | |
tree | eabeb6ae52ae80f42ccb34bf479a60748989bf59 | |
parent | e177123f0c2d77ed2fde724ca352166ca9464619 (diff) |
Driver core: Protect device shutdown from hot unplug events.
While device_shutdown() walks through devices_kset to shutdown all
devices, device unplug events may race to shutdown individual devices.
Specifically, sd_shutdown(), on behalf of fc_starget_delete(), has
been observed deleting devices during device_shutdown()'s list
traversal. So we factor out list_for_each_entry_safe_reverse(...) in
favor of while (!list_empty(...)).
Signed-off-by: Hugh Daschbach <hdasch@broadcom.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/base/core.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index 4c5be85016b6..356dd011b8f9 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -1734,10 +1734,25 @@ EXPORT_SYMBOL_GPL(device_move); | |||
1734 | */ | 1734 | */ |
1735 | void device_shutdown(void) | 1735 | void device_shutdown(void) |
1736 | { | 1736 | { |
1737 | struct device *dev, *devn; | 1737 | struct device *dev; |
1738 | |||
1739 | spin_lock(&devices_kset->list_lock); | ||
1740 | /* | ||
1741 | * Walk the devices list backward, shutting down each in turn. | ||
1742 | * Beware that device unplug events may also start pulling | ||
1743 | * devices offline, even as the system is shutting down. | ||
1744 | */ | ||
1745 | while (!list_empty(&devices_kset->list)) { | ||
1746 | dev = list_entry(devices_kset->list.prev, struct device, | ||
1747 | kobj.entry); | ||
1748 | get_device(dev); | ||
1749 | /* | ||
1750 | * Make sure the device is off the kset list, in the | ||
1751 | * event that dev->*->shutdown() doesn't remove it. | ||
1752 | */ | ||
1753 | list_del_init(&dev->kobj.entry); | ||
1754 | spin_unlock(&devices_kset->list_lock); | ||
1738 | 1755 | ||
1739 | list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, | ||
1740 | kobj.entry) { | ||
1741 | if (dev->bus && dev->bus->shutdown) { | 1756 | if (dev->bus && dev->bus->shutdown) { |
1742 | dev_dbg(dev, "shutdown\n"); | 1757 | dev_dbg(dev, "shutdown\n"); |
1743 | dev->bus->shutdown(dev); | 1758 | dev->bus->shutdown(dev); |
@@ -1745,6 +1760,10 @@ void device_shutdown(void) | |||
1745 | dev_dbg(dev, "shutdown\n"); | 1760 | dev_dbg(dev, "shutdown\n"); |
1746 | dev->driver->shutdown(dev); | 1761 | dev->driver->shutdown(dev); |
1747 | } | 1762 | } |
1763 | put_device(dev); | ||
1764 | |||
1765 | spin_lock(&devices_kset->list_lock); | ||
1748 | } | 1766 | } |
1767 | spin_unlock(&devices_kset->list_lock); | ||
1749 | async_synchronize_full(); | 1768 | async_synchronize_full(); |
1750 | } | 1769 | } |