[SCSI] sd: check runtime PM status in sd_shutdown
authorLin Ming <ming.m.lin@intel.com>
Mon, 5 Dec 2011 01:20:26 +0000 (09:20 +0800)
committerJeff Garzik <jgarzik@redhat.com>
Mon, 9 Jan 2012 00:14:57 +0000 (19:14 -0500)
sd_shutdown is called during reboot/poweroff.
It may fail if parent device, for example, ata port, was runtime suspended.

Fix it by checking runtime PM status of sd.
Exit immediately if sd was runtime suspended already.

Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
drivers/scsi/sd.c

index fa3a5918009cfd9e9223a650a6c487585af36fa4..7b3f8075e2a5d9f53e8f4d322ff5756fd496b51b 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/string_helpers.h>
 #include <linux/async.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 #include <asm/uaccess.h>
 #include <asm/unaligned.h>
 
@@ -2741,6 +2742,9 @@ static void sd_shutdown(struct device *dev)
        if (!sdkp)
                return;         /* this can happen */
 
+       if (pm_runtime_suspended(dev))
+               goto exit;
+
        if (sdkp->WCE) {
                sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
                sd_sync_cache(sdkp);
@@ -2751,6 +2755,7 @@ static void sd_shutdown(struct device *dev)
                sd_start_stop_device(sdkp, 0);
        }
 
+exit:
        scsi_disk_put(sdkp);
 }