aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/core.c25
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 */
1735void device_shutdown(void) 1735void 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}