Skip to content

Commit

Permalink
usb: fix wrong capacity report for USB mass storage device
Browse files Browse the repository at this point in the history
Usb "write" method never copies the input data buffer, it uses the
buffer pointer directly. The fact that it was on the stack made
the buffer ephemeral, and could disappear before the USB transfer
actually occurred. The data transmitted was then random. This commit
converts the transfer buffer to a static buffer, so that it always
exists for the duration of the USB transfer.

Known side-effect: if "read capacity" command is read twice
simultaneously, the same buffer will be used twice. As the capacity of a
USB drive should not change between 2 calls, this side effect can be
ignored.

Signed-off-by: Alexi Demers <alexi.demers@axceta.com>
(cherry picked from commit 32481b6)
  • Loading branch information
ademers-axceta authored and jfischer-no committed Aug 27, 2024
1 parent e84c516 commit 3c4fe42
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion subsys/usb/device/class/msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ static bool readFormatCapacity(void)

static bool readCapacity(void)
{
uint8_t capacity[8];
static uint8_t capacity[8];

sys_put_be32(block_count - 1, &capacity[0]);
sys_put_be32(BLOCK_SIZE, &capacity[4]);
Expand Down

0 comments on commit 3c4fe42

Please sign in to comment.