diff mbox series

[v1,1/3] driver core: move core part of device_shutdown() to a separate function

Message ID 20231124145338.3112416-2-o.rempel@pengutronix.de
State New
Headers show
Series introduce priority-based shutdown support | expand

Commit Message

Oleksij Rempel Nov. 24, 2023, 2:53 p.m. UTC
Split the device_shutdown() as a preparation for the prioritization
support.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/base/core.c | 110 +++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 47 deletions(-)

Comments

Greg KH Nov. 24, 2023, 3:07 p.m. UTC | #1
On Fri, Nov 24, 2023 at 03:53:36PM +0100, Oleksij Rempel wrote:
> Split the device_shutdown() as a preparation for the prioritization
> support.

Nit, this is going to need a lot more description, as at this point in
time, we do not know what "prioritization support" is.

> 
> Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
> ---
>  drivers/base/core.c | 110 +++++++++++++++++++++++++-------------------
>  1 file changed, 63 insertions(+), 47 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 67ba592afc77..0f5646a097d3 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4719,12 +4719,73 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
>  }
>  EXPORT_SYMBOL_GPL(device_change_owner);
>  
> +/**

This doesn't need kernel-doc for a static function, right?

> + * device_shutdown_one - shut down a device
> + * @dev: device to shut down
> + *
> + * It is called with the device lock held.
> + *
> + * The device must be on the devices_kset list.
> + */
> +static void device_shutdown_one_locked(struct device *dev)
> +{
> +	struct device *parent;
> +
> +	lockdep_assert_held(&devices_kset->list_lock);
> +	/*
> +	 * 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);
> +	/*

As you are moving the code, might as well make it a bit prettier and add
proper line breaks before the comments please.

thanks,

greg k-h
kernel test robot Nov. 24, 2023, 8:04 p.m. UTC | #2
Hi Oleksij,

kernel test robot noticed the following build warnings:

[auto build test WARNING on driver-core/driver-core-testing]
[also build test WARNING on driver-core/driver-core-next driver-core/driver-core-linus linus/master v6.7-rc2 next-20231124]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oleksij-Rempel/driver-core-move-core-part-of-device_shutdown-to-a-separate-function/20231124-225602
base:   driver-core/driver-core-testing
patch link:    https://lore.kernel.org/r/20231124145338.3112416-2-o.rempel%40pengutronix.de
patch subject: [PATCH v1 1/3] driver core: move core part of device_shutdown() to a separate function
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20231125/202311250213.Ba7c2l5R-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231125/202311250213.Ba7c2l5R-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311250213.Ba7c2l5R-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/base/core.c:4731: warning: expecting prototype for device_shutdown_one(). Prototype was for device_shutdown_one_locked() instead


vim +4731 drivers/base/core.c

b8f33e5d76a7a1 Christian Brauner  2020-02-27  4721  
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4722  /**
52950bfb3bedfc Oleksij Rempel     2023-11-24  4723   * device_shutdown_one - shut down a device
52950bfb3bedfc Oleksij Rempel     2023-11-24  4724   * @dev: device to shut down
52950bfb3bedfc Oleksij Rempel     2023-11-24  4725   *
52950bfb3bedfc Oleksij Rempel     2023-11-24  4726   * It is called with the device lock held.
52950bfb3bedfc Oleksij Rempel     2023-11-24  4727   *
52950bfb3bedfc Oleksij Rempel     2023-11-24  4728   * The device must be on the devices_kset list.
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4729   */
52950bfb3bedfc Oleksij Rempel     2023-11-24  4730  static void device_shutdown_one_locked(struct device *dev)
37b0c020343080 Greg Kroah-Hartman 2007-11-26 @4731  {
52950bfb3bedfc Oleksij Rempel     2023-11-24  4732  	struct device *parent;
d1c6c030fcec6f Ming Lei           2012-06-22  4733  
52950bfb3bedfc Oleksij Rempel     2023-11-24  4734  	lockdep_assert_held(&devices_kset->list_lock);
d1c6c030fcec6f Ming Lei           2012-06-22  4735  	/*
d1c6c030fcec6f Ming Lei           2012-06-22  4736  	 * hold reference count of device's parent to
d1c6c030fcec6f Ming Lei           2012-06-22  4737  	 * prevent it from being freed because parent's
d1c6c030fcec6f Ming Lei           2012-06-22  4738  	 * lock is to be held
d1c6c030fcec6f Ming Lei           2012-06-22  4739  	 */
f123db8e9d6c84 Benson Leung       2013-09-24  4740  	parent = get_device(dev->parent);
6245838fe4d2ce Hugh Daschbach     2010-03-22  4741  	get_device(dev);
6245838fe4d2ce Hugh Daschbach     2010-03-22  4742  	/*
6245838fe4d2ce Hugh Daschbach     2010-03-22  4743  	 * Make sure the device is off the kset list, in the
6245838fe4d2ce Hugh Daschbach     2010-03-22  4744  	 * event that dev->*->shutdown() doesn't remove it.
6245838fe4d2ce Hugh Daschbach     2010-03-22  4745  	 */
6245838fe4d2ce Hugh Daschbach     2010-03-22  4746  	list_del_init(&dev->kobj.entry);
6245838fe4d2ce Hugh Daschbach     2010-03-22  4747  	spin_unlock(&devices_kset->list_lock);
fe6b91f47080eb Alan Stern         2011-12-06  4748  
d1c6c030fcec6f Ming Lei           2012-06-22  4749  	/* hold lock to avoid race with probe/release */
f123db8e9d6c84 Benson Leung       2013-09-24  4750  	if (parent)
f123db8e9d6c84 Benson Leung       2013-09-24  4751  		device_lock(parent);
d1c6c030fcec6f Ming Lei           2012-06-22  4752  	device_lock(dev);
d1c6c030fcec6f Ming Lei           2012-06-22  4753  
fe6b91f47080eb Alan Stern         2011-12-06  4754  	/* Don't allow any more runtime suspends */
fe6b91f47080eb Alan Stern         2011-12-06  4755  	pm_runtime_get_noresume(dev);
fe6b91f47080eb Alan Stern         2011-12-06  4756  	pm_runtime_barrier(dev);
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4757  
7521621e600aee Michal Suchanek    2017-08-11  4758  	if (dev->class && dev->class->shutdown_pre) {
f77af151658474 Josh Zimmerman     2017-06-25  4759  		if (initcall_debug)
7521621e600aee Michal Suchanek    2017-08-11  4760  			dev_info(dev, "shutdown_pre\n");
7521621e600aee Michal Suchanek    2017-08-11  4761  		dev->class->shutdown_pre(dev);
7521621e600aee Michal Suchanek    2017-08-11  4762  	}
7521621e600aee Michal Suchanek    2017-08-11  4763  	if (dev->bus && dev->bus->shutdown) {
0246c4fafccd6c ShuoX Liu          2012-11-23  4764  		if (initcall_debug)
0246c4fafccd6c ShuoX Liu          2012-11-23  4765  			dev_info(dev, "shutdown\n");
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4766  		dev->bus->shutdown(dev);
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4767  	} else if (dev->driver && dev->driver->shutdown) {
0246c4fafccd6c ShuoX Liu          2012-11-23  4768  		if (initcall_debug)
0246c4fafccd6c ShuoX Liu          2012-11-23  4769  			dev_info(dev, "shutdown\n");
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4770  		dev->driver->shutdown(dev);
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4771  	}
d1c6c030fcec6f Ming Lei           2012-06-22  4772  
d1c6c030fcec6f Ming Lei           2012-06-22  4773  	device_unlock(dev);
f123db8e9d6c84 Benson Leung       2013-09-24  4774  	if (parent)
f123db8e9d6c84 Benson Leung       2013-09-24  4775  		device_unlock(parent);
d1c6c030fcec6f Ming Lei           2012-06-22  4776  
6245838fe4d2ce Hugh Daschbach     2010-03-22  4777  	put_device(dev);
f123db8e9d6c84 Benson Leung       2013-09-24  4778  	put_device(parent);
6245838fe4d2ce Hugh Daschbach     2010-03-22  4779  
6245838fe4d2ce Hugh Daschbach     2010-03-22  4780  	spin_lock(&devices_kset->list_lock);
37b0c020343080 Greg Kroah-Hartman 2007-11-26  4781  }
52950bfb3bedfc Oleksij Rempel     2023-11-24  4782
diff mbox series

Patch

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 67ba592afc77..0f5646a097d3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4719,12 +4719,73 @@  int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
 }
 EXPORT_SYMBOL_GPL(device_change_owner);
 
+/**
+ * device_shutdown_one - shut down a device
+ * @dev: device to shut down
+ *
+ * It is called with the device lock held.
+ *
+ * The device must be on the devices_kset list.
+ */
+static void device_shutdown_one_locked(struct device *dev)
+{
+	struct device *parent;
+
+	lockdep_assert_held(&devices_kset->list_lock);
+	/*
+	 * 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;
 
 	wait_for_device_probe();
 	device_block_probing();
@@ -4741,52 +4802,7 @@  void device_shutdown(void)
 		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_one_locked(dev);
 	}
 	spin_unlock(&devices_kset->list_lock);
 }