Skip to content

Commit 366ba7c

Browse files
Flameeyesaxboe
authored andcommitted
cdrom: respect device capabilities during opening action
Reading the TOC only works if the device can play audio, otherwise these commands fail (and possibly bring the device to an unhealthy state.) Similarly, cdrom_mmc3_profile() should only be called if the device supports generic packet commands. To: Jens Axboe <axboe@kernel.dk> Cc: linux-kernel@vger.kernel.org Cc: linux-scsi@vger.kernel.org Signed-off-by: Diego Elio Pettenò <flameeyes@flameeyes.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent be2eca9 commit 366ba7c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎drivers/cdrom/cdrom.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks)
996996
tracks->xa = 0;
997997
tracks->error = 0;
998998
cd_dbg(CD_COUNT_TRACKS, "entering cdrom_count_tracks\n");
999+
1000+
if (!CDROM_CAN(CDC_PLAY_AUDIO)) {
1001+
tracks->error = CDS_NO_INFO;
1002+
return;
1003+
}
1004+
9991005
/* Grab the TOC header so we can see how many tracks there are */
10001006
ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header);
10011007
if (ret) {
@@ -1162,7 +1168,8 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
11621168
ret = open_for_data(cdi);
11631169
if (ret)
11641170
goto err;
1165-
cdrom_mmc3_profile(cdi);
1171+
if (CDROM_CAN(CDC_GENERIC_PACKET))
1172+
cdrom_mmc3_profile(cdi);
11661173
if (mode & FMODE_WRITE) {
11671174
ret = -EROFS;
11681175
if (cdrom_open_write(cdi))
@@ -2882,6 +2889,9 @@ int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written)
28822889
it doesn't give enough information or fails. then we return
28832890
the toc contents. */
28842891
use_toc:
2892+
if (!CDROM_CAN(CDC_PLAY_AUDIO))
2893+
return -ENOSYS;
2894+
28852895
toc.cdte_format = CDROM_MSF;
28862896
toc.cdte_track = CDROM_LEADOUT;
28872897
if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc)))

0 commit comments

Comments
 (0)