Skip to content

Commit 99bee6a

Browse files
committed
ehci: fix removed qhd get reused
Signed-off-by: HiFiPhile <[email protected]>
1 parent 4db2bda commit 99bee6a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/host/usbh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ static bool usbh_control_xfer_cb (uint8_t daddr, uint8_t ep_addr, xfer_result_t
844844
const uint8_t ep_status = tu_edpt_addr(0, 1 - request->bmRequestType_bit.direction);
845845
TU_ASSERT(hcd_edpt_xfer(rhport, daddr, ep_status, NULL, 0));
846846
break;
847-
}
847+
}
848848

849849
case CONTROL_STAGE_ACK: {
850850
// Abort all pending transfers if SET_CONFIGURATION request

src/portable/ehci/ehci.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include "host/hcd.h"
3737
#include "host/usbh.h"
38+
#include "host/usbh_pvt.h"
3839
#include "ehci_api.h"
3940
#include "ehci.h"
4041

@@ -866,14 +867,21 @@ static ehci_qhd_t *qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr) {
866867
}
867868

868869
ehci_qhd_t *qhd_pool = ehci_data.qhd_pool;
870+
871+
// protect qhd_pool since 'used' and 'removing' can be changed in isr
872+
ehci_qhd_t *result = NULL;
873+
usbh_spin_lock(false);
869874
for (uint32_t i = 0; i < QHD_MAX; i++) {
870875
if ((qhd_pool[i].dev_addr == dev_addr) &&
871-
ep_addr == qhd_ep_addr(&qhd_pool[i])) {
872-
return &qhd_pool[i];
876+
ep_addr == qhd_ep_addr(&qhd_pool[i]) &&
877+
qhd_pool[i].used && !qhd_pool[i].removing) {
878+
result = &qhd_pool[i];
879+
break;
873880
}
874881
}
882+
usbh_spin_unlock(false);
875883

876-
return NULL;
884+
return result;
877885
}
878886

879887
// Init queue head with endpoint descriptor

0 commit comments

Comments
 (0)