Skip to content

Commit 95dc756

Browse files
Stuart Hayesgregkh
authored andcommitted
driver core: separate function to shutdown one device
Make a separate function for the part of device_shutdown() that does the shutown for a single device. This is in preparation for making device shutdown asynchronous. Signed-off-by: Stuart Hayes <[email protected]> Signed-off-by: David Jeffery <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Keith Busch <[email protected]> Tested-by: Keith Busch <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ba63537 commit 95dc756

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

drivers/base/core.c

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,6 +4779,41 @@ int device_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid)
47794779
}
47804780
EXPORT_SYMBOL_GPL(device_change_owner);
47814781

4782+
static void shutdown_one_device(struct device *dev)
4783+
{
4784+
/* hold lock to avoid race with probe/release */
4785+
if (dev->parent && dev->bus && dev->bus->need_parent_lock)
4786+
device_lock(dev->parent);
4787+
device_lock(dev);
4788+
4789+
/* Don't allow any more runtime suspends */
4790+
pm_runtime_get_noresume(dev);
4791+
pm_runtime_barrier(dev);
4792+
4793+
if (dev->class && dev->class->shutdown_pre) {
4794+
if (initcall_debug)
4795+
dev_info(dev, "shutdown_pre\n");
4796+
dev->class->shutdown_pre(dev);
4797+
}
4798+
if (dev->bus && dev->bus->shutdown) {
4799+
if (initcall_debug)
4800+
dev_info(dev, "shutdown\n");
4801+
dev->bus->shutdown(dev);
4802+
} else if (dev->driver && dev->driver->shutdown) {
4803+
if (initcall_debug)
4804+
dev_info(dev, "shutdown\n");
4805+
dev->driver->shutdown(dev);
4806+
}
4807+
4808+
device_unlock(dev);
4809+
if (dev->parent && dev->bus && dev->bus->need_parent_lock)
4810+
device_unlock(dev->parent);
4811+
4812+
put_device(dev);
4813+
if (dev->parent)
4814+
put_device(dev->parent);
4815+
}
4816+
47824817
/**
47834818
* device_shutdown - call ->shutdown() on each device to shutdown.
47844819
*/
@@ -4815,36 +4850,7 @@ void device_shutdown(void)
48154850
list_del_init(&dev->kobj.entry);
48164851
spin_unlock(&devices_kset->list_lock);
48174852

4818-
/* hold lock to avoid race with probe/release */
4819-
if (parent && dev->bus && dev->bus->need_parent_lock)
4820-
device_lock(parent);
4821-
device_lock(dev);
4822-
4823-
/* Don't allow any more runtime suspends */
4824-
pm_runtime_get_noresume(dev);
4825-
pm_runtime_barrier(dev);
4826-
4827-
if (dev->class && dev->class->shutdown_pre) {
4828-
if (initcall_debug)
4829-
dev_info(dev, "shutdown_pre\n");
4830-
dev->class->shutdown_pre(dev);
4831-
}
4832-
if (dev->bus && dev->bus->shutdown) {
4833-
if (initcall_debug)
4834-
dev_info(dev, "shutdown\n");
4835-
dev->bus->shutdown(dev);
4836-
} else if (dev->driver && dev->driver->shutdown) {
4837-
if (initcall_debug)
4838-
dev_info(dev, "shutdown\n");
4839-
dev->driver->shutdown(dev);
4840-
}
4841-
4842-
device_unlock(dev);
4843-
if (parent && dev->bus && dev->bus->need_parent_lock)
4844-
device_unlock(parent);
4845-
4846-
put_device(dev);
4847-
put_device(parent);
4853+
shutdown_one_device(dev);
48484854

48494855
spin_lock(&devices_kset->list_lock);
48504856
}

0 commit comments

Comments
 (0)