Skip to content

Commit a8974d4

Browse files
committed
drivers: serial: nrfx_uarte: Fix race in uart_rx_disable due to RXTO event
Fixes a race condition where uart_rx_disable() is interrupted by RXTO ISR, which can corrupt internal driver state. The IRQ lock is now taken earlier to ensure atomic access to RX buffer and flags. Tested on nRF52840 at 460800 baud using Modbus RTU. Fixes: #92777 Signed-off-by: Anouar Raddaoui <a.raddaoui@smight.com>
1 parent b3ccee4 commit a8974d4

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/serial/uart_nrfx_uarte.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,19 +1282,18 @@ static int uarte_nrfx_callback_set(const struct device *dev,
12821282

12831283
static int uarte_nrfx_rx_disable(const struct device *dev)
12841284
{
1285+
int key = irq_lock();
12851286
struct uarte_nrfx_data *data = dev->data;
12861287
struct uarte_async_rx *async_rx = &data->async->rx;
12871288
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
1288-
int key;
12891289

12901290
if (async_rx->buf == NULL) {
1291+
irq_unlock(key);
12911292
return -EFAULT;
12921293
}
12931294

12941295
k_timer_stop(&async_rx->timer);
12951296

1296-
key = irq_lock();
1297-
12981297
if (async_rx->next_buf != NULL) {
12991298
nrf_uarte_shorts_disable(uarte, NRF_UARTE_SHORT_ENDRX_STARTRX);
13001299
nrf_uarte_event_clear(uarte, NRF_UARTE_EVENT_RXSTARTED);

0 commit comments

Comments
 (0)