From c3e2a045a19a63dda3538d84cb0dc8a37ec5d814 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 17 Jul 2023 11:15:48 +0200 Subject: [PATCH] RP2040: Fix null dereference in usb_lld_disable_endpoints 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. --- os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c | 33 ------------------------ 1 file changed, 33 deletions(-) diff --git a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c index 5512dbbdb8..d0afaa2a26 100644 --- a/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c +++ b/os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c @@ -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. */ @@ -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; } }