Home Home > GIT Browse > SLE15-AZURE
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Duncan <lduncan@suse.com>2019-09-06 13:24:24 -0700
committerLee Duncan <lduncan@suse.com>2019-09-06 13:24:24 -0700
commitacbf76350d673078b3a4889022b7a54d94b45929 (patch)
tree991457efe7ff22be900ad2ef63d18017288b251b
parent22b5a94c18dc72eefc3c9a2c8f392697e9a46624 (diff)
- scsi: sr: Avoid that opening a CD-ROM hangs with runtime power
management enabled (git-fixes). - Refresh patches.suse/scsi-sr-wait-for-the-medium-to-become-ready.patch. suse-commit: 9ec2045562423fd7b83c2b80c4a460ff3f28646d
-rw-r--r--drivers/scsi/sr.c52
1 files changed, 34 insertions, 18 deletions
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 1c8ff3562caf..bd881730657d 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -523,28 +523,39 @@ static int sr_init_command(struct scsi_cmnd *SCpnt)
static int sr_block_open(struct block_device *bdev, fmode_t mode)
{
struct scsi_cd *cd;
+ struct scsi_device *sdev;
int ret = -ENXIO;
+ cd = scsi_cd_get(bdev->bd_disk);
+ if (!cd)
+ goto out;
+
+ sdev = cd->device;
+ scsi_autopm_get_device(sdev);
check_disk_change(bdev);
mutex_lock(&sr_mutex);
- cd = scsi_cd_get(bdev->bd_disk);
- if (cd) {
- ret = cdrom_open(&cd->cdi, bdev, mode);
- /* wait for drive to get ready */
- if ((ret == -ENOMEDIUM) && !(mode & FMODE_NDELAY))
- switch (sr_disk_status(&cd->cdi)) {
- case CDS_NO_DISC:
- case CDS_NO_INFO:
- case CDS_AUDIO:
- break;;
- default: /* looks like data disc was detected */
- ret = cdrom_open(&cd->cdi, bdev, mode);
- }
- if (ret)
- scsi_cd_put(cd);
- }
+ ret = cdrom_open(&cd->cdi, bdev, mode);
mutex_unlock(&sr_mutex);
+
+ /* wait for drive to get ready */
+ if ((ret == -ENOMEDIUM) && !(mode & FMODE_NDELAY))
+ switch (sr_disk_status(&cd->cdi)) {
+ case CDS_NO_DISC:
+ case CDS_NO_INFO:
+ case CDS_AUDIO:
+ break;;
+ default: /* looks like data disc was detected */
+ mutex_lock(&sr_mutex);
+ ret = cdrom_open(&cd->cdi, bdev, mode);
+ mutex_unlock(&sr_mutex);
+ }
+
+ scsi_autopm_put_device(sdev);
+ if (ret)
+ scsi_cd_put(cd);
+
+out:
return ret;
}
@@ -572,6 +583,8 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
if (ret)
goto out;
+ scsi_autopm_get_device(sdev);
+
/*
* Send SCSI addressing ioctls directly to mid level, send other
* ioctls to cdrom/block level.
@@ -580,15 +593,18 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
case SCSI_IOCTL_GET_IDLUN:
case SCSI_IOCTL_GET_BUS_NUMBER:
ret = scsi_ioctl(sdev, cmd, argp);
- goto out;
+ goto put;
}
ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
if (ret != -ENOSYS)
- goto out;
+ goto put;
ret = scsi_ioctl(sdev, cmd, argp);
+put:
+ scsi_autopm_put_device(sdev);
+
out:
mutex_unlock(&sr_mutex);
return ret;