Skip to content

Commit 36b6ed8

Browse files
committed
nrf5x: Fix EP OUT race conditions in OS build
When two tasks entered dcd_edpt_xfer() it was possible that first disabled interrupt to setup total_len and actual_len but second task for another endpoint enabled interrupt between total_len and actual_len resulting in race condition with interrupt, hence mutex is added on top of interrupt being blocked.
1 parent 980ffe3 commit 36b6ed8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/portable/nordic/nrf5x/dcd_nrf5x.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,17 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
463463

464464
xfer_td_t* xfer = get_td(epnum, dir);
465465

466-
dcd_int_disable(rhport);
466+
if (!is_in_isr()) {
467+
osal_mutex_lock(dcd_mutex, OSAL_TIMEOUT_WAIT_FOREVER);
468+
dcd_int_disable(rhport);
469+
}
467470
xfer->buffer = buffer;
468471
xfer->total_len = total_bytes;
469472
xfer->actual_len = 0;
470-
dcd_int_enable(rhport);
473+
if (!is_in_isr()) {
474+
dcd_int_enable(rhport);
475+
osal_mutex_unlock(dcd_mutex);
476+
}
471477

472478
// Control endpoint with zero-length packet and opposite direction to 1st request byte --> status stage
473479
bool const control_status = (epnum == 0 && total_bytes == 0 && dir != tu_edpt_dir(NRF_USBD->BMREQUESTTYPE));

0 commit comments

Comments
 (0)