diff mbox series

[v5,1/3] drivers core: refactor device_shutdown

Message ID 20180516024004.28977-2-pasha.tatashin@oracle.com
State Awaiting Upstream
Headers show
Series [v5,1/3] drivers core: refactor device_shutdown | expand

Commit Message

Pavel Tatashin May 16, 2018, 2:40 a.m. UTC
device_shutdown() traverses through the list of devices, and calls
dev->{bug/driver}->shutdown() for each entry in the list.

Refactor the function by keeping device_shutdown() to do the logic of
traversing the list of devices, and device_shutdown_one() to perform the
actual shutdown operation on one device.

Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
---
 drivers/base/core.c | 50 +++++++++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 20 deletions(-)

Comments

Andy Shevchenko June 5, 2018, 4:44 p.m. UTC | #1
On Wed, May 16, 2018 at 5:40 AM, Pavel Tatashin
<pasha.tatashin@oracle.com> wrote:
> device_shutdown() traverses through the list of devices, and calls
> dev->{bug/driver}->shutdown() for each entry in the list.
>
> Refactor the function by keeping device_shutdown() to do the logic of
> traversing the list of devices, and device_shutdown_one() to perform the
> actual shutdown operation on one device.
>

FWIW,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
> ---
>  drivers/base/core.c | 50 +++++++++++++++++++++++++++------------------
>  1 file changed, 30 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index b610816eb887..ed189f6d1a2f 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -2765,6 +2765,35 @@ int device_move(struct device *dev, struct device *new_parent,
>  }
>  EXPORT_SYMBOL_GPL(device_move);
>
> +/*
> + * device_shutdown_one - call ->shutdown() for the device passed as
> + * argument.
> + */
> +static void device_shutdown_one(struct device *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);
> +       }
> +
> +       /* decrement the reference counter */
> +       put_device(dev);
> +}
> +
>  /**
>   * device_shutdown - call ->shutdown() on each device to shutdown.
>   */
> @@ -2801,30 +2830,11 @@ void device_shutdown(void)
>                         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_shutdown_one(dev);
>                 device_unlock(dev);
>                 if (parent)
>                         device_unlock(parent);
>
> -               put_device(dev);
>                 put_device(parent);
>
>                 spin_lock(&devices_kset->list_lock);
> --
> 2.17.0
>
Pavel Tatashin June 5, 2018, 5:14 p.m. UTC | #2
> FWIW,
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>

Thank you Andy.

Pavel
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index b610816eb887..ed189f6d1a2f 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2765,6 +2765,35 @@  int device_move(struct device *dev, struct device *new_parent,
 }
 EXPORT_SYMBOL_GPL(device_move);
 
+/*
+ * device_shutdown_one - call ->shutdown() for the device passed as
+ * argument.
+ */
+static void device_shutdown_one(struct device *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);
+	}
+
+	/* decrement the reference counter */
+	put_device(dev);
+}
+
 /**
  * device_shutdown - call ->shutdown() on each device to shutdown.
  */
@@ -2801,30 +2830,11 @@  void device_shutdown(void)
 			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_shutdown_one(dev);
 		device_unlock(dev);
 		if (parent)
 			device_unlock(parent);
 
-		put_device(dev);
 		put_device(parent);
 
 		spin_lock(&devices_kset->list_lock);