From 37c4fd3b50fa0fc2548331859e4e7df369a1ca73 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 25 Jun 2018 23:39:46 +1000 Subject: [PATCH] stm32/mboot: Fix bug with invalid memory access of USB state. Only one of pcd_fs_handle/pcd_hs_handle is ever initialised, so if both of these USB peripherals are enabled then one of these if-statements will access invalid memory pointed to by an uninitialised Instance. This patch fixes this bug by explicitly referencing the peripheral struct. --- ports/stm32/mboot/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm32/mboot/main.c b/ports/stm32/mboot/main.c index 11053971bc..f75d9809bf 100644 --- a/ports/stm32/mboot/main.c +++ b/ports/stm32/mboot/main.c @@ -1249,12 +1249,12 @@ enter_bootloader: for (;;) { #if USE_USB_POLLING #if defined(MICROPY_HW_USB_FS) - if (pcd_fs_handle.Instance->GINTSTS & pcd_fs_handle.Instance->GINTMSK) { + if (USB_OTG_FS->GINTSTS & USB_OTG_FS->GINTMSK) { HAL_PCD_IRQHandler(&pcd_fs_handle); } #endif #if defined(MICROPY_HW_USB_HS) - if (pcd_hs_handle.Instance->GINTSTS & pcd_hs_handle.Instance->GINTMSK) { + if (USB_OTG_HS->GINTSTS & USB_OTG_HS->GINTMSK) { HAL_PCD_IRQHandler(&pcd_hs_handle); } #endif