Skip to content

Commit 50255fa

Browse files
committed
Limit USB control transfer size
Limit the size of control reads to the max packet size of endpoint zero. This fixes the handling of large transfers.
1 parent a211fe1 commit 50255fa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

usb/device/USBDevice/USBDevice.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#endif
5050
#define MAX_PACKET_SIZE_EP0 64
5151

52+
#define USB_MIN(a, b) ((a) > (b) ? (b) : (a))
53+
5254

5355
bool USBDevice::_request_get_descriptor()
5456
{
@@ -224,7 +226,7 @@ bool USBDevice::_control_out()
224226
complete_request_xfer_done(true);
225227
}
226228
} else {
227-
_phy->ep0_read(_transfer.ptr, _transfer.remaining);
229+
_phy->ep0_read(_transfer.ptr, USB_MIN(_transfer.remaining, _max_packet_size_ep0));
228230
}
229231

230232
return true;
@@ -800,7 +802,7 @@ void USBDevice::_control_setup_continue()
800802
} else {
801803
/* OUT stage */
802804
_transfer.stage = DataOut;
803-
_phy->ep0_read(_transfer.ptr, _transfer.remaining);
805+
_phy->ep0_read(_transfer.ptr, USB_MIN(_transfer.remaining, _max_packet_size_ep0));
804806
}
805807
} else {
806808
/* Status stage */

0 commit comments

Comments
 (0)