[PATCH] usb: storage: shuttle_usbat: do not divide by an unknown sector size

From: YuanZhe Liu

Date: Mon Nov 16 2026 - 04:35:21 EST


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 when a READ CAPACITY command has completed successfully, 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

Reject read and write requests while the sector size is unknown, the same
way the driver already rejects an out of range LBA.

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>
---
drivers/usb/storage/shuttle_usbat.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index 7e5424268c73..faea2c77c5aa 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -1130,6 +1130,13 @@ static int usbat_flash_read_data(struct us_data *us,
if (result != USB_STOR_TRANSPORT_GOOD)
return result;

+ /*
+ * The sector size is only known once a READ CAPACITY command has
+ * succeeded; a request can arrive before that.
+ */
+ if (!info->ssize)
+ return USB_STOR_TRANSPORT_ERROR;
+
/*
* we're working in LBA mode. according to the ATA spec,
* we can support up to 28-bit addressing. I don't know if Jumpshot
@@ -1221,6 +1228,13 @@ static int usbat_flash_write_data(struct us_data *us,
if (result != USB_STOR_TRANSPORT_GOOD)
return result;

+ /*
+ * The sector size is only known once a READ CAPACITY command has
+ * succeeded; a request can arrive before that.
+ */
+ if (!info->ssize)
+ return USB_STOR_TRANSPORT_ERROR;
+
/*
* we're working in LBA mode. according to the ATA spec,
* we can support up to 28-bit addressing. I don't know if the device
--
2.34.1