Re: [PATCH v2 2/2] cdrom: gdrom: update gendisk capacity on open

Artur Rojek
2026-04-19T16:59:43Z

On 2026-04-19 18:28, Florian Fuchs wrote:
> Update the gendisk capacity of the media. Without the capacity, the
> block
> reads fail before reaching the request queue, which prevented ISO9660
> mounts. Refresh the capacity from the TOC leadout in gdrom_bdops_open()
> so it checks the inserted media.
>
> Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
> ---
> v1->v2: no change for gdrom_update_capacity(), but for
> gdrom_bdops_open(): handle the failure case when
> gdrom_update_capacity() fails but previous cdrom_open()
> succeeded,
> to cleanup the successful cdrom_open() with cdrom_release()
>
> v1:
> https://lore.kernel.org/linux-sh/20260405082330.4104672-3-fuchsfl@gmail.com/
> ---
> drivers/cdrom/gdrom.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
> index 89938d9b2825..fb95288fad72 100644
> --- a/drivers/cdrom/gdrom.c
> +++ b/drivers/cdrom/gdrom.c
> @@ -474,6 +474,25 @@ static const struct cdrom_device_ops gdrom_ops = {
> CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
> };
>
> +static int gdrom_update_capacity(void)
> +{
> + sector_t cap;
> + int ret;
> +
> + if (gdrom_drivestatus(gd.cd_info, CDSL_CURRENT) != CDS_DISC_OK) {
> + set_capacity(gd.disk, 0);
> + return -ENOMEDIUM;
> + }
> + ret = gdrom_readtoc_cmd(gd.toc, 0);
> + if (ret) {
> + set_capacity(gd.disk, 0);
> + return ret;
> + }
> + cap = (sector_t)get_entry_lba(gd.toc->leadout) * GD_TO_BLK;
> + set_capacity(gd.disk, cap);
> + return 0;
> +}
> +
> static int gdrom_bdops_open(struct gendisk *disk, blk_mode_t mode)
> {
> int ret;
> @@ -482,6 +501,12 @@ static int gdrom_bdops_open(struct gendisk *disk,
> blk_mode_t mode)
>
> mutex_lock(&gdrom_mutex);
> ret = cdrom_open(gd.cd_info, mode);
> + if (ret)
> + goto out;
> + ret = gdrom_update_capacity();
> + if (ret)
> + cdrom_release(gd.cd_info);
> +out:
> mutex_unlock(&gdrom_mutex);
> return ret;
> }

Hey Florian,

thanks for v2!

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

PS. I found the reason behind mount failing for the first time after
a disc swap - you need to send a dummy 0x0 SPI command to "sink"
the pending UNIT_ATTENTION error, otherwise it will permeate at
the next command executed, which in our case is gdrom_preparedisk_cmd().

I already sent you a WIP patch via IRC. Once you test it, would you
consider including it in this series and sending v3?

Cheers,
Artur