From 3ccef09b4e01e221bde3e9ad2c21ec67635c0734 Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Sat, 5 Jun 2021 13:51:31 +0900 Subject: [PATCH] drivers: serial: Remove an unnecessary critical section (cs) for SMP Summary: - I thought this cs is needed to avoid data corruption - For example, while executing uart_xmitchar() in the interrupt handler on CPU0, an application running on CPU1 can call uart_putxmitchar() via write()->uart_write(). - In this case, taking xmit.sem in uart_write() will wait for CPU0 to finish uart_xmitchar() because CPU0 has already taken a cs in uart_xmitchar() then nxsem_wait() on CPU0 takes a new cs inside (and release the cs when returning but it's OK) - Then uart_write() on CPU1 disables UART TX, so uart_xmitchar() on CPU0 will not be called while executing uart_write() on CPU1. - So this critical section in uart_putxmitchar() can be removed. Impact: - None Testing: - Tested with spresense:wifi_smp, esp32-devkitc:smp Reported-by: Xiang Xiao Signed-off-by: Masayuki Ishikawa --- drivers/serial/serial.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 4394a52bbb..1de8076ce3 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -191,10 +191,6 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) int nexthead; int ret; -#ifdef CONFIG_SMP - irqstate_t flags2 = enter_critical_section(); -#endif - /* Increment to see what the next head pointer will be. * We need to use the "next" head pointer to determine when the circular * buffer would overrun @@ -330,10 +326,6 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch, bool oktoblock) err_out: -#ifdef CONFIG_SMP - leave_critical_section(flags2); -#endif - return ret; }