Skip to content

Commit bf96c5a

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 dbcbd87 commit bf96c5a

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
@@ -1103,20 +1103,26 @@ static int uarte_nrfx_rx_disable(const struct device *dev)
11031103
struct uarte_nrfx_data *data = dev->data;
11041104
struct uarte_async_rx *rdata = &data->async->rx;
11051105
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
1106+
int key;
11061107

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

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

11191124
nrf_uarte_task_trigger(uarte, NRF_UARTE_TASK_STOPRX);
1125+
irq_unlock(key);
11201126

11211127
return 0;
11221128
}

0 commit comments

Comments
 (0)