public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Daan De Meyer <daan.j.demeyer@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: James.Bottomley@HansenPartnership.com,
	martin.petersen@oracle.com, Daan De Meyer <daan@amutable.com>,
	Daan De Meyer <daan.j.demeyer@gmail.com>
Subject: [PATCH] scsi: sr: exclude CDC_MRW_W and CDC_RAM from writeable check
Date: Mon, 30 Mar 2026 13:34:03 +0000	[thread overview]
Message-ID: <20260330133403.796330-1-daan@amutable.com> (raw)

The writeable check in get_capabilities() includes CDC_MRW_W and
CDC_RAM in its bitmask, but these capabilities are not determined from
the MODE SENSE capabilities page. They require the SCSI GET
CONFIGURATION command, which is only issued later by cdrom_open_write()
at device open time.

Since cdi.mask is initialized to zero (all capabilities assumed
present), CDC_MRW_W and CDC_RAM are left unmasked by default. This
makes the writeable check always true when MODE SENSE succeeds,
regardless of the drive's actual write capabilities as reported in the
capabilities page.

Fix this by only checking CDC_DVD_RAM and CDC_CD_RW in the writeable
condition, as these are the write capabilities actually determined from
the MODE SENSE capabilities page. CDC_MRW_W and CDC_RAM will continue
to be evaluated by cdrom_open_write() at open time via GET
CONFIGURATION.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Daan De Meyer <daan.j.demeyer@gmail.com>
---
 drivers/scsi/sr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 8ed002f82e36..0a6413b77dd3 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -901,10 +901,14 @@ static int get_capabilities(struct scsi_cd *cd)
 		cd->cdi.mask |= CDC_CLOSE_TRAY; */
 
 	/*
-	 * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
+	 * Check if the drive has write capabilities. Only consider
+	 * capabilities that are determined from the MODE SENSE capabilities
+	 * page here. CDC_MRW_W (MRW writing) and CDC_RAM (random writable)
+	 * require the SCSI GET CONFIGURATION command to determine, which
+	 * is issued later by cdrom_open_write() at device open time.
 	 */
-	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
-			(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
+	if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_CD_RW)) !=
+			(CDC_DVD_RAM | CDC_CD_RW)) {
 		cd->writeable = 1;
 	}
 
-- 
2.53.0


                 reply	other threads:[~2026-03-30 13:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260330133403.796330-1-daan@amutable.com \
    --to=daan.j.demeyer@gmail.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=daan@amutable.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox