public inbox for linux-sh@vger.kernel.org
 help / color / mirror / Atom feed
From: Florian Fuchs <fuchsfl@gmail.com>
To: linux-sh@vger.kernel.org,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	Artur Rojek <contact@artur-rojek.eu>
Cc: Adrian McMenamin <adrianmcmenamin@gmail.com>,
	linux-kernel@vger.kernel.org, Florian Fuchs <fuchsfl@gmail.com>
Subject: [PATCH v3 3/3] cdrom: gdrom: verify device access after disc swap
Date: Thu, 23 Apr 2026 21:41:32 +0200	[thread overview]
Message-ID: <20260423194132.693271-4-fuchsfl@gmail.com> (raw)
In-Reply-To: <20260423194132.693271-1-fuchsfl@gmail.com>

From: Artur Rojek <contact@artur-rojek.eu>

To ready the drive for cdrom_open(), this driver sends a spin disc
command. However, if the cd lid has been opened and the disc de-spinned,
the very next SPI command will return UNIT_ATTENTION sense error,
resulting in a failure to mount the disc.

Fix this by sending a dummy TEST_UNIT command, which will catch the
above error, and allow subsequent commands to execute correctly.

Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
---
v3: new patch added from Artur Rojek and also verified that it works.

 drivers/cdrom/gdrom.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 1e73617b39ac..21ef4657dd2b 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -219,6 +219,33 @@ static char gdrom_execute_diagnostic(void)
 	return __raw_readb(GDROM_ERROR_REG);
 }
 
+/*
+ * Test unit command
+ * byte 0 = 0x0
+ *
+ * This command verifies whether device can be accessed.
+ *
+ * -EIO indicates that device is not ready for operation.
+ */
+static int gdrom_test_unit_cmd(void)
+{
+	struct packet_command *test_command;
+
+	test_command = kzalloc_obj(struct packet_command);
+	if (!test_command)
+		return -ENOMEM;
+	test_command->cmd[0] = 0x0;
+	test_command->buflen = 0;
+	gd.pending = 1;
+	gdrom_packetcommand(gd.cd_info, test_command);
+	wait_event_interruptible_timeout(command_queue, gd.pending == 0,
+					 GDROM_DEFAULT_TIMEOUT);
+	gd.pending = 0;
+	kfree(test_command);
+
+	return gd.status & 0x1 ? -EIO : 0;
+}
+
 /*
  * Prepare disk command
  * byte 0 = 0x70
@@ -353,6 +380,9 @@ static int gdrom_get_last_session(struct cdrom_device_info *cd_info,
 
 static int gdrom_open(struct cdrom_device_info *cd_info, int purpose)
 {
+	/* Sink pending UNIT_ATTENTION sense error after a disc swap. */
+	(void)gdrom_test_unit_cmd();
+
 	/* spin up the disk */
 	return gdrom_preparedisk_cmd();
 }
-- 
2.43.0


      parent reply	other threads:[~2026-04-23 20:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 19:41 [PATCH v3 0/3] cdrom: gdrom: fix block I/O and capacity setting Florian Fuchs
2026-04-23 19:41 ` [PATCH v3 1/3] cdrom: gdrom: replace port I/O with MMIO accessors Florian Fuchs
2026-04-23 19:41 ` [PATCH v3 2/3] cdrom: gdrom: update gendisk capacity on open Florian Fuchs
2026-04-24 18:57   ` Artur Rojek
2026-04-23 19:41 ` Florian Fuchs [this message]

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=20260423194132.693271-4-fuchsfl@gmail.com \
    --to=fuchsfl@gmail.com \
    --cc=adrianmcmenamin@gmail.com \
    --cc=contact@artur-rojek.eu \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /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