Skip to content

Commit

Permalink
bugfix(otgfs): Remove wrong assertions
Browse files Browse the repository at this point in the history
ExplodingWaffle pointed out[1] the host is allowed to send a shorter
packet than what we were expecting. Remove the assertions and links to
embassy.

[1] #59 (comment)

Reported-by: Harry Brooke <harry.brooke1@hotmail.co.uk>
  • Loading branch information
Codetector1374 committed Nov 3, 2024
1 parent fffd45c commit 5fad626
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/otg_fs/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,8 @@ impl<'d, T: Instance> embassy_usb_driver::EndpointOut for Endpoint<'d, T, Out> {
// upper bits are reserved (0)
let len = regs.rx_len().read().0 as usize;

// Assertion exists because looks like embassy-usb expects no partial reads.
// https://github.com/embassy-rs/embassy/blob/6e0b08291b63a0da8eba9284869d1d046bc5dabb/embassy-usb/src/lib.rs#L408
debug_assert_eq!(len, buf.len());
if len == buf.len() {
self.data.buffer.read_volatile(&mut buf[..len]);
Poll::Ready(Ok(len))
} else {
Poll::Ready(Err(EndpointError::BufferOverflow))
}
self.data.buffer.read_volatile(&mut buf[..len]);
Poll::Ready(Ok(len))
}
token => {
error!("Unexpected USB Token {}", token.to_bits());
Expand Down Expand Up @@ -286,20 +279,11 @@ where
let res = match status.mask_token() {
UsbToken::OUT => {
let len = regs.rx_len().read().0 as usize;
// https://github.com/embassy-rs/embassy/blob/6e0b08291b63a0da8eba9284869d1d046bc5dabb/embassy-usb/src/lib.rs#L408
// Embassy expects the whole buffer to be filled
let res = if len == buf.len() {
self.ep0_buf.buffer.read_volatile(&mut buf[..len]);
Poll::Ready(Ok(len))
} else {
Poll::Ready(Err(EndpointError::BufferOverflow))
};

self.ep0_buf.buffer.read_volatile(&mut buf[..len]);
regs.uep_rx_ctrl(0).modify(|v| {
v.set_mask_r_res(EpRxResponse::NAK);
});

res
Poll::Ready(Ok(len))
}
UsbToken::RSVD | UsbToken::IN | UsbToken::SETUP => unreachable!(),
};
Expand Down

0 comments on commit 5fad626

Please sign in to comment.