[PATCH v9 04/11] scsi: sr: initialize logical block size before registering the disk

From: Phil Pemberton

Date: Tue Oct 06 2026 - 19:42:49 EST


sr_probe() sets sdev->sector_size to 2048, but the request queue keeps its
512-byte default until revalidation finds ready media. Booting a COMPAQ
PD-1 LF-1195C with a PD inserted leaves the empty CD LUN with mismatched
block sizes. Later CD reads can fail with "unaligned transfer".

After initial revalidation, set the queue's logical block size to
sdev->sector_size if they differ. Do this before registering the disk,
and unwind the probe if the update fails.

Revalidation must run first so ready media can supply the actual block
size. Applying the 2048-byte default earlier would raise the physical
block size and minimum I/O size, which stay raised if revalidation later
finds 512-byte sectors.

Assisted-by: LLM
Signed-off-by: Phil Pemberton <philpem@xxxxxxxxxxxxx>
---
drivers/scsi/sr.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index c36c54ecd354..268f15a4fdb8 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -619,6 +619,7 @@ static void sr_release(struct cdrom_device_info *cdi)
static int sr_probe(struct scsi_device *sdev)
{
struct device *dev = &sdev->sdev_gendev;
+ struct queue_limits lim;
struct gendisk *disk;
struct scsi_cd *cd;
int minor, error;
@@ -701,6 +702,16 @@ static int sr_probe(struct scsi_device *sdev)
if (error)
goto unregister_cdrom;

+ /* If no medium was ready, match the queue to the driver's guess. */
+ if (queue_logical_block_size(sdev->request_queue) != sdev->sector_size) {
+ lim = queue_limits_start_update(sdev->request_queue);
+ lim.logical_block_size = sdev->sector_size;
+ error = queue_limits_commit_update_frozen(sdev->request_queue,
+ &lim);
+ if (error)
+ goto unregister_cdrom;
+ }
+
error = device_add_disk(&sdev->sdev_gendev, disk, NULL);
if (error)
goto unregister_cdrom;
--
2.43.0