Pack the code into a function to ease the using and reading.

Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
Cc: Grygorii Strashko <grygorii.stras...@ti.com>
Cc: Christoph Hellwig <h...@infradead.org>
Cc: Bjorn Helgaas <helg...@kernel.org>
Cc: Dave Young <dyo...@redhat.com>
Cc: linux-...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Pingfan Liu <kernelf...@gmail.com>
---
 drivers/base/core.c | 100 +++++++++++++++++++++++++++-------------------------
 1 file changed, 52 insertions(+), 48 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index df3e1a4..a48868f 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2802,12 +2802,62 @@ int device_move(struct device *dev, struct device 
*new_parent,
 }
 EXPORT_SYMBOL_GPL(device_move);
 
+static void __device_shutdown(struct device *dev)
+{
+       struct device *parent;
+       /*
+        * hold reference count of device's parent to
+        * prevent it from being freed because parent's
+        * lock is to be held
+        */
+       parent = get_device(dev->parent);
+       get_device(dev);
+       /*
+        * Make sure the device is off the kset list, in the
+        * event that dev->*->shutdown() doesn't remove it.
+        */
+       list_del_init(&dev->kobj.entry);
+       spin_unlock(&devices_kset->list_lock);
+
+       /* hold lock to avoid race with probe/release */
+       if (parent)
+               device_lock(parent);
+       device_lock(dev);
+
+       /* Don't allow any more runtime suspends */
+       pm_runtime_get_noresume(dev);
+       pm_runtime_barrier(dev);
+
+       if (dev->class && dev->class->shutdown_pre) {
+               if (initcall_debug)
+                       dev_info(dev, "shutdown_pre\n");
+               dev->class->shutdown_pre(dev);
+       }
+       if (dev->bus && dev->bus->shutdown) {
+               if (initcall_debug)
+                       dev_info(dev, "shutdown\n");
+               dev->bus->shutdown(dev);
+       } else if (dev->driver && dev->driver->shutdown) {
+               if (initcall_debug)
+                       dev_info(dev, "shutdown\n");
+               dev->driver->shutdown(dev);
+       }
+
+       device_unlock(dev);
+       if (parent)
+               device_unlock(parent);
+
+       put_device(dev);
+       put_device(parent);
+       spin_lock(&devices_kset->list_lock);
+}
+
 /**
  * device_shutdown - call ->shutdown() on each device to shutdown.
  */
 void device_shutdown(void)
 {
-       struct device *dev, *parent;
+       struct device *dev;
 
        spin_lock(&devices_kset->list_lock);
        /*
@@ -2818,53 +2868,7 @@ void device_shutdown(void)
        while (!list_empty(&devices_kset->list)) {
                dev = list_entry(devices_kset->list.prev, struct device,
                                kobj.entry);
-
-               /*
-                * hold reference count of device's parent to
-                * prevent it from being freed because parent's
-                * lock is to be held
-                */
-               parent = get_device(dev->parent);
-               get_device(dev);
-               /*
-                * Make sure the device is off the kset list, in the
-                * event that dev->*->shutdown() doesn't remove it.
-                */
-               list_del_init(&dev->kobj.entry);
-               spin_unlock(&devices_kset->list_lock);
-
-               /* hold lock to avoid race with probe/release */
-               if (parent)
-                       device_lock(parent);
-               device_lock(dev);
-
-               /* Don't allow any more runtime suspends */
-               pm_runtime_get_noresume(dev);
-               pm_runtime_barrier(dev);
-
-               if (dev->class && dev->class->shutdown_pre) {
-                       if (initcall_debug)
-                               dev_info(dev, "shutdown_pre\n");
-                       dev->class->shutdown_pre(dev);
-               }
-               if (dev->bus && dev->bus->shutdown) {
-                       if (initcall_debug)
-                               dev_info(dev, "shutdown\n");
-                       dev->bus->shutdown(dev);
-               } else if (dev->driver && dev->driver->shutdown) {
-                       if (initcall_debug)
-                               dev_info(dev, "shutdown\n");
-                       dev->driver->shutdown(dev);
-               }
-
-               device_unlock(dev);
-               if (parent)
-                       device_unlock(parent);
-
-               put_device(dev);
-               put_device(parent);
-
-               spin_lock(&devices_kset->list_lock);
+               __device_shutdown(dev);
        }
        spin_unlock(&devices_kset->list_lock);
 }
-- 
2.7.4

Reply via email to