diff options
author | Pingfan Liu <kernelfans@gmail.com> | 2018-07-19 01:14:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-07-21 03:51:44 -0400 |
commit | 3297c8fc65af5d40501ea7cddff1b195cae57e4e (patch) | |
tree | bb4fe13f55f81955b1dcedc61ab1c1cb2cd510bc | |
parent | 726e41097920a73e4c7c33385dcc0debb1281e18 (diff) |
drivers/base: stop new probing during shutdown
There is a race window in device_shutdown(), which may cause
-1. parent device shut down before child or
-2. no shutdown on a new probing device.
For 1st, taking the following scenario:
device_shutdown new plugin device
list_del_init(parent_dev);
spin_unlock(list_lock);
device_add(child)
probe child
shutdown parent_dev
--> now child is on the tail of devices_kset
For 2nd, taking the following scenario:
device_shutdown new plugin device
device_add(dev)
device_lock(dev);
...
device_unlock(dev);
probe dev
--> now, the new occurred dev has no opportunity to shutdown
To fix this race issue, just prevent the new probing request. With this
logic, device_shutdown() is more similar to dpm_prepare().
Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/base/core.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c index cf8c605ec32e..5411af447418 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -2811,6 +2811,9 @@ void device_shutdown(void) | |||
2811 | { | 2811 | { |
2812 | struct device *dev, *parent; | 2812 | struct device *dev, *parent; |
2813 | 2813 | ||
2814 | wait_for_device_probe(); | ||
2815 | device_block_probing(); | ||
2816 | |||
2814 | spin_lock(&devices_kset->list_lock); | 2817 | spin_lock(&devices_kset->list_lock); |
2815 | /* | 2818 | /* |
2816 | * Walk the devices list backward, shutting down each in turn. | 2819 | * Walk the devices list backward, shutting down each in turn. |