Re: [usb-storage] [PATCH v2] usb: storage: shuttle_usbat: set the ATA sector size at device init
From: Alan Stern
Date: Tue Nov 17 2026 - 15:35:41 EST
On Tue, Nov 17, 2026 at 09:27:07AM +0800, 'YuanZhe Liu' via USB Mass Storage on Linux wrote:
> usbat_flash_read_data() and usbat_flash_write_data() divide the transfer
> length by info->ssize to turn it into an ATA sector count. info->ssize is
> only assigned in the READ CAPACITY handler, so it is still zero when a
> read request arrives earlier.
>
> Such a request is sent during device scan: sd_probe() starts with
> media_present set and usb-storage sets read_before_ms for every device, so
> sd_revalidate_disk() calls sd_read_block_zero() right after
> sd_read_capacity(), even when READ CAPACITY failed, because
> read_capacity_error() deliberately keeps media_present set for drives that
> fail it with media loaded. A CompactFlash reader that does not complete
> the READ CAPACITY sequence, for example because a register access is
> stalled, therefore reaches usbat_flash_read_data() with info->ssize == 0:
>
> Oops: divide error
> RIP: 0010:usbat_flash_read_data+0x2a4/0x5c0
>
> The ATA sector size of these readers is fixed at 512 bytes, so record it
> when the USBAT flash transport is selected, instead of waiting for a READ
> CAPACITY command to succeed. The datafab and jumpshot drivers, which
> share this code, already set it during device identification for the same
> reason.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Cc: stable@xxxxxxxxxxxxxxx
> Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
> ---
> Changes in v2:
> - Set info->ssize when the flash transport is selected, as suggested by
> Alan Stern, so the value is always available.
> - Drop the assignment from the READ CAPACITY handler, now redundant.
> ---
Acked-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
> drivers/usb/storage/shuttle_usbat.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
> index 7e5424268c73..267c82381465 100644
> --- a/drivers/usb/storage/shuttle_usbat.c
> +++ b/drivers/usb/storage/shuttle_usbat.c
> @@ -1038,6 +1038,8 @@ static int usbat_set_transport(struct us_data *us,
> break;
>
> case USBAT_DEV_FLASH:
> + /* The ATA sector size of these readers is fixed at 512 bytes */
> + info->ssize = 0x200;
> us->transport = usbat_flash_transport;
> break;
> }
> @@ -1703,8 +1705,6 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
> if (rc != USB_STOR_TRANSPORT_GOOD)
> return rc;
>
> - /* hard coded 512 byte sectors as per ATA spec */
> - info->ssize = 0x200;
> usb_stor_dbg(us, "READ_CAPACITY: %ld sectors, %ld bytes per sector\n",
> info->sectors, info->ssize);
>
> --
> 2.34.1