Skip to content

Commit 18ebfe5

Browse files
EricNRSaescolar
authored andcommitted
drivers: serial: esp32_usb: fix interrupt-enable race condition
After enabling interrupts, serial_esp32_usb_irq_tx_enable() calls the interrupt handler to handle any old events that occurred while interrupts were disabled. However, this happens in the callers context, so if an interrupt arrives during the call, it will call the interrupt handler again resulting in corruption if the interrupt handler is not reentrant. Fixes #74569 Signed-off-by: Eric Holmberg <[email protected]>
1 parent 41c9ec3 commit 18ebfe5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/serial/serial_esp32_usb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ static void serial_esp32_usb_irq_tx_enable(const struct device *dev)
142142
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
143143

144144
if (data->irq_cb != NULL) {
145+
unsigned int key = irq_lock();
145146
data->irq_cb(dev, data->irq_cb_data);
147+
arch_irq_unlock(key);
146148
}
147149
}
148150

@@ -220,8 +222,8 @@ static void serial_esp32_usb_irq_callback_set(const struct device *dev,
220222
{
221223
struct serial_esp32_usb_data *data = dev->data;
222224

223-
data->irq_cb = cb;
224225
data->irq_cb_data = cb_data;
226+
data->irq_cb = cb;
225227
}
226228

227229
static void serial_esp32_usb_isr(void *arg)

0 commit comments

Comments
 (0)