[SCSI] scsi_pm: set device runtime state before parent suspended
authorLin Ming <ming.m.lin@intel.com>
Fri, 6 Jul 2012 04:06:57 +0000 (12:06 +0800)
committerJames Bottomley <JBottomley@Parallels.com>
Fri, 20 Jul 2012 07:58:55 +0000 (08:58 +0100)
There is a race in scsi_bus_resume_common when set device's runtime
state to active after pm_runtime_put_sync(dev->parent).

Parent device may have been suspended so pm_runtime_set_active(dev) will
fail with -EBUSY.

Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
drivers/scsi/scsi_pm.c

index d4201de..dc0ad85 100644 (file)
@@ -76,23 +76,24 @@ static int scsi_bus_resume_common(struct device *dev)
 {
        int err = 0;
 
-       if (scsi_is_sdev_device(dev)) {
-               /*
-                * Parent device may have runtime suspended as soon as
-                * it is woken up during the system resume.
-                *
-                * Resume it on behalf of child.
-                */
-               pm_runtime_get_sync(dev->parent);
-               err = scsi_dev_type_resume(dev);
-               pm_runtime_put_sync(dev->parent);
-       }
+       /*
+        * Parent device may have runtime suspended as soon as
+        * it is woken up during the system resume.
+        *
+        * Resume it on behalf of child.
+        */
+       pm_runtime_get_sync(dev->parent);
 
+       if (scsi_is_sdev_device(dev))
+               err = scsi_dev_type_resume(dev);
        if (err == 0) {
                pm_runtime_disable(dev);
                pm_runtime_set_active(dev);
                pm_runtime_enable(dev);
        }
+
+       pm_runtime_put_sync(dev->parent);
+
        return err;
 }