From 11f06eb0f5f505439fd0ab91abc7df09d84e712d Mon Sep 17 00:00:00 2001 From: fangpeina Date: Mon, 27 May 2024 10:37:54 +0800 Subject: [PATCH] drivers/serial: fix deadlock when executing rexec in a user task CPU0 CPU1 task:nsh_main task:user_app rexecd nsh_consolemain system uart_read rexec --- got recv.lock poll --- uart_poll rpmsg_socket_poll rpmsg_socket_close wait recvsem get recv.lock poll_notify deadlock routine work the error accurs in CPU0 when waiting console input resolve: unlock recv.lock when waiting recvsem Signed-off-by: fangpeina --- drivers/serial/serial.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index c1f9ac8a73..ef00bfa1df 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -1052,15 +1052,19 @@ static ssize_t uart_read(FAR struct file *filep, dev->minrecv = MIN(buflen - recvd, dev->minread - recvd); if (dev->timeout) { + nxmutex_unlock(&dev->recv.lock); ret = nxsem_tickwait(&dev->recvsem, DSEC2TICK(dev->timeout)); } else #endif { + nxmutex_unlock(&dev->recv.lock); ret = nxsem_wait(&dev->recvsem); } + nxmutex_lock(&dev->recv.lock); + #ifdef CONFIG_SERIAL_TERMIOS dev->minrecv = dev->minread; #endif