From: Ana Bobillo <anabobillo3@gmail.com>
To: Tom Rini <trini@konsulko.com>
Cc: u-boot@lists.u-boot-project.org, Simon Glass <sjg@chromium.org>,
Marek Vasut <marek.vasut+usb@mailbox.org>,
Bin Meng <bmeng.cn@gmail.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Alexey Charkov <alchark@flipper.net>,
Javier Martinez Canillas <javierm@redhat.com>
Subject: [PATCH v4 03/14] usb: storage: Fix the capacity faked when READ CAPACITY fails
Date: Wed, 04 Nov 2026 12:50:42 +0000 [thread overview]
Message-ID: <a6f346ff-1865-4c75-a86e-aa2be64ab185@gmail.com> (raw)
In-Reply-To: <1369653d-e0d4-4baf-adef-895a24190250@gmail.com>
From: Ana Bobillo <anabobillo3@gmail.com>
When READ CAPACITY fails, usb_stor_get_info() makes up a reply of its own
for a 1.44MB floppy, 2880 blocks of 512 bytes. But it sets the values in
host byte order, while the reply is read back as big endian, so on a
little-endian host the device gets 0x400b0001 blocks (about 1G) of 128KiB
rather than 2880 of 512 bytes. It also puts 2880 where READ CAPACITY
returns the last LBA, so even on a big-endian host the device gets 2881
blocks.
Set the reply in big endian like the one it stands in for, with 2879 as
the last LBA, so that such a device has 2880 blocks of 512 bytes on any
host.
Fixes: 149dded2b178 ("* Add support for USB Mass Storage Devices (BBB) (tested with USB memory sticks only)")
Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
(no changes since v2)
Changes in v2:
- New patch, split out of v1 patch 2, with a Fixes: tag (Simon)
- Give 2879 as the last LBA, so that the device has 2880 blocks (Simon)
common/usb_storage.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/usb_storage.c b/common/usb_storage.c
index ac331f1c1b0..f7c96195b59 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -1496,8 +1496,9 @@ int usb_stor_get_info(struct usb_device *dev, struct us_data *ss,
if (usb_read_capacity(pccb, ss) != 0) {
printf("READ_CAP ERROR\n");
ss->flags &= ~USB_READY;
- cap[0] = 2880;
- cap[1] = 0x200;
+ /* a 1.44MB floppy, as READ CAPACITY gives it: last LBA, size */
+ cap[0] = cpu_to_be32(2880 - 1);
+ cap[1] = cpu_to_be32(0x200);
}
debug("Read Capacity returns: 0x%08x, 0x%08x\n", cap[0], cap[1]);
#if 0
next prev parent reply other threads:[~2026-11-04 12:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 12:50 [PATCH v4 00/14] block, disk: Check block sizes and partition tables of devices Ana Bobillo
2026-11-04 12:50 ` [PATCH v4 01/14] treewide: Use is_power_of_2() from linux/log2.h Ana Bobillo
2026-11-04 12:50 ` [PATCH v4 02/14] block: Add blk_valid_blksz() to check a block size Ana Bobillo
2026-11-04 12:50 ` Ana Bobillo [this message]
2026-11-04 12:50 ` [PATCH v4 04/14] usb: storage: Refuse a block size the block layer cannot use Ana Bobillo
2026-11-04 12:50 ` [PATCH v4 05/14] scsi: " Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 06/14] ide: Refuse an ATAPI block size atapi_read() cannot read Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 07/14] nvme: Skip a namespace with an unsupported LBA data size Ana Bobillo
2026-11-11 8:14 ` Neil Armstrong
2026-11-04 12:51 ` [PATCH v4 08/14] block: Refuse a device with an unsupported block size Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 09/14] disk: part_efi: Check the header and entry sizes of a GPT Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 10/14] disk: part_dos: Walk the extended partition tables in a bounded loop Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 11/14] disk: part_dos: Number at most 255 partitions, as Linux does Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 12/14] efi_loader: Measure the GPT the partition driver uses Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 13/14] efi_loader: Index the GPT entries directly in tcg2_measure_gpt_data() Ana Bobillo
2026-11-04 12:51 ` [PATCH v4 14/14] mmc: Always use a 512-byte block length Ana Bobillo
2026-11-09 9:33 ` Peng Fan
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=a6f346ff-1865-4c75-a86e-aa2be64ab185@gmail.com \
--to=anabobillo3@gmail.com \
--cc=alchark@flipper.net \
--cc=bmeng.cn@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=javierm@redhat.com \
--cc=marek.vasut+usb@mailbox.org \
--cc=neil.armstrong@linaro.org \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
--cc=xypron.glpk@gmx.de \
/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