[AUTOSEL,4.14,61/67] drivers/base: stop new probing during shutdown
diff mbox series

Message ID 20180907003716.57737-61-alexander.levin@microsoft.com
State New, archived
Headers show
  • [AUTOSEL,4.14,01/67] usb: dwc3: change stream event enable bit back to 13
Related show

Commit Message

Sasha Levin Sept. 7, 2018, 12:38 a.m. UTC
From: Pingfan Liu <kernelfans@gmail.com>

[ Upstream commit 3297c8fc65af5d40501ea7cddff1b195cae57e4e ]

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
                                                  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
                                                  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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
 drivers/base/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff mbox series

diff --git a/drivers/base/core.c b/drivers/base/core.c
index b054cb2fd2b9..eb066cc827ef 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2783,6 +2783,9 @@  void device_shutdown(void)
 	struct device *dev, *parent;
+	wait_for_device_probe();
+	device_block_probing();
 	 * Walk the devices list backward, shutting down each in turn.