Skip to content

Commit 6cc41f0

Browse files
committed
return early after raising USBError
This commit makes sure that functions in usb.core.Device return as soon as they raise a MicroPython exception rather than continuing on with whatever code would normally run. This will hopefully help to avoid things like dereferencing null pointers.
1 parent 154ef2e commit 6cc41f0

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

shared-module/usb/core/Device.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static size_t _xfer(tuh_xfer_t *xfer, mp_int_t timeout) {
160160
xfer->complete_cb = _transfer_done_cb;
161161
if (!tuh_edpt_xfer(xfer)) {
162162
mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer"));
163+
return 0;
163164
}
164165
uint32_t start_time = supervisor_ticks_ms32();
165166
while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) &&
@@ -206,6 +207,7 @@ static bool _open_endpoint(usb_core_device_obj_t *self, mp_int_t endpoint) {
206207

207208
if (self->configuration_descriptor == NULL) {
208209
mp_raise_usb_core_USBError(MP_ERROR_TEXT("NoCfg"));
210+
return false;
209211
}
210212

211213
tusb_desc_configuration_t *desc_cfg = (tusb_desc_configuration_t *)self->configuration_descriptor;
@@ -288,6 +290,7 @@ mp_int_t common_hal_usb_core_device_ctrl_transfer(usb_core_device_obj_t *self,
288290

289291
if (!tuh_control_xfer(&xfer)) {
290292
mp_raise_usb_core_USBError(MP_ERROR_TEXT("Xfer"));
293+
return 0;
291294
}
292295
uint32_t start_time = supervisor_ticks_ms32();
293296
while ((timeout == 0 || supervisor_ticks_ms32() - start_time < (uint32_t)timeout) &&

0 commit comments

Comments
 (0)