Skip to content

Commit 97a28ab

Browse files
committed
[nrf fromlist] drivers: serial: nrfx_uarte: Add lock to uart_rx_disable
Add lock to fix race when uart_rx_disable is interrupted by RXTO event which lead to driver state corruption. Upstream PR: zephyrproject-rtos/zephyr#75462 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 1346c93 commit 97a28ab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,20 +1102,26 @@ static int uarte_nrfx_rx_disable(const struct device *dev)
11021102
struct uarte_nrfx_data *data = dev->data;
11031103
struct uarte_async_rx *rdata = &data->async->rx;
11041104
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
1105+
int key;
11051106

11061107
if (rdata->buf == NULL) {
11071108
return -EFAULT;
11081109
}
1110+
1111+
k_timer_stop(&rdata->timer);
1112+
1113+
key = irq_lock();
1114+
11091115
if (rdata->next_buf != NULL) {
11101116
nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX);
11111117
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED);
11121118
}
11131119

1114-
k_timer_stop(&rdata->timer);
11151120
rdata->enabled = false;
11161121
rdata->discard_fifo = true;
11171122

11181123
nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX);
1124+
irq_unlock(key);
11191125

11201126
return 0;
11211127
}

0 commit comments

Comments
 (0)