Skip to content

Commit

Permalink
[SCSI] sd: Add runtime pm in the sd_check_events()
Browse files Browse the repository at this point in the history
The sd_check_event() will be called periodly even when the device is in the
suspended status to check media event. The scsi_test_unit_ready() in the
sd_check_event() will issue scsi cmd request. Issuing scsi request when the
device is in the suspeneded status will cause problem. For example, when a usb
flash disk in the suspended status, scsi_test_unit_ready() issues a scsi
request. The request will be returned as failed because the usb device is not
active. The patch adds scsi_autopm_get_device() and scsi_autopm_put_device()
around scsi_test_unit_ready() in the sd_check_event() to resolve such problem.

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
  • Loading branch information
Lan Tianyu authored and James Bottomley committed Mar 19, 2012
1 parent cd8df93 commit 4e2247b
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,14 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
retval = -ENODEV;

if (scsi_block_when_processing_errors(sdp)) {
retval = scsi_autopm_get_device(sdp);
if (retval)
goto out;

sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
sshdr);
scsi_autopm_put_device(sdp);
}

/* failed to execute TUR, assume media not present */
Expand Down

0 comments on commit 4e2247b

Please sign in to comment.