Skip to content

Commit

Permalink
RP2040: Fix null dereference in usb_lld_disable_endpoints
Browse files Browse the repository at this point in the history
usb_lld_disable_endpoints is called by usbDisableEndpointsI, which
already sets all endpoint configurations to NULL before. This will
always lead to a hardfault. The fix is simple though, just remove the
interaction.
  • Loading branch information
KarlK90 committed Jul 17, 2023
1 parent aa12996 commit c3e2a04
Showing 1 changed file with 0 additions and 33 deletions.
33 changes: 0 additions & 33 deletions os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,6 @@ static void reset_ep0(USBDriver *usbp) {
usbp->epc[0]->in_state->stalled = false;
}

#if 0
/**
* @brief Reset specified endpoint.
*/
static void reset_endpoint(USBDriver *usbp, usbep_t ep, bool is_in) {
const USBEndpointConfig *epcp = usbp->epc[ep];

if (is_in) {
USBInEndpointState *in_state = epcp->in_state;
if (in_state) {
in_state->active = false;
in_state->stalled = false;
in_state->next_pid = 0U;
}
} else {
USBOutEndpointState *out_state = epcp->out_state;
if (out_state) {
out_state->active = false;
out_state->stalled = false;
out_state->next_pid = 0U;
}
}
}
#endif

/**
* @brief Prepare buffer for receiving data.
*/
Expand Down Expand Up @@ -689,16 +664,8 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
* @notapi
*/
void usb_lld_disable_endpoints(USBDriver *usbp) {
/* Ignore zero */
for (uint8_t ep = 1; ep <= USB_ENDOPOINTS_NUMBER; ep++) {
usbp->epc[ep]->in_state->active = false;
usbp->epc[ep]->in_state->stalled = false;
usbp->epc[ep]->in_state->next_pid = 0;
EP_CTRL(ep).IN &= ~USB_EP_EN;

usbp->epc[ep]->out_state->active = false;
usbp->epc[ep]->out_state->stalled = false;
usbp->epc[ep]->out_state->next_pid = 0;
EP_CTRL(ep).OUT &= ~USB_EP_EN;
}
}
Expand Down

0 comments on commit c3e2a04

Please sign in to comment.