Commit 86f47a23 authored by Diego Elio Pettenò's avatar Diego Elio Pettenò Committed by Kleber Sacilotto de Souza

cdrom: respect device capabilities during opening action

BugLink: https://bugs.launchpad.net/bugs/1858462

[ Upstream commit 366ba7c7 ]

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: default avatarDiego Elio Pettenò <flameeyes@flameeyes.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 020a7e99
...@@ -998,6 +998,12 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks) ...@@ -998,6 +998,12 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks)
tracks->xa = 0; tracks->xa = 0;
tracks->error = 0; tracks->error = 0;
cd_dbg(CD_COUNT_TRACKS, "entering cdrom_count_tracks\n"); cd_dbg(CD_COUNT_TRACKS, "entering cdrom_count_tracks\n");
if (!CDROM_CAN(CDC_PLAY_AUDIO)) {
tracks->error = CDS_NO_INFO;
return;
}
/* Grab the TOC header so we can see how many tracks there are */ /* Grab the TOC header so we can see how many tracks there are */
ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header); ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCHDR, &header);
if (ret) { if (ret) {
...@@ -1164,7 +1170,8 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, ...@@ -1164,7 +1170,8 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
ret = open_for_data(cdi); ret = open_for_data(cdi);
if (ret) if (ret)
goto err; goto err;
cdrom_mmc3_profile(cdi); if (CDROM_CAN(CDC_GENERIC_PACKET))
cdrom_mmc3_profile(cdi);
if (mode & FMODE_WRITE) { if (mode & FMODE_WRITE) {
ret = -EROFS; ret = -EROFS;
if (cdrom_open_write(cdi)) if (cdrom_open_write(cdi))
...@@ -2863,6 +2870,9 @@ int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written) ...@@ -2863,6 +2870,9 @@ int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written)
it doesn't give enough information or fails. then we return it doesn't give enough information or fails. then we return
the toc contents. */ the toc contents. */
use_toc: use_toc:
if (!CDROM_CAN(CDC_PLAY_AUDIO))
return -ENOSYS;
toc.cdte_format = CDROM_MSF; toc.cdte_format = CDROM_MSF;
toc.cdte_track = CDROM_LEADOUT; toc.cdte_track = CDROM_LEADOUT;
if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc))) if ((ret = cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &toc)))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment