]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drivers/base: stop new probing during shutdown
authorPingfan Liu <kernelfans@gmail.com>
Thu, 19 Jul 2018 05:14:58 +0000 (13:14 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 21 Jul 2018 07:51:44 +0000 (09:51 +0200)
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>
drivers/base/core.c

index cf8c605ec32eaeb65cc3f234d68ee91cc4d7286c..5411af44741809b4d02b5865c4c6aed415ce4534 100644 (file)
@@ -2811,6 +2811,9 @@ void device_shutdown(void)
 {
        struct device *dev, *parent;
 
+       wait_for_device_probe();
+       device_block_probing();
+
        spin_lock(&devices_kset->list_lock);
        /*
         * Walk the devices list backward, shutting down each in turn.