From 0aae54ae977860d0f17f6312d078ae39fa8c324d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B3=BD=E5=A0=82?= <130895816+sexenteen@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:16:53 +0800 Subject: [PATCH] =?UTF-8?q?[drivers][serial]=20=E4=BF=9D=E7=95=99=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E4=B8=B2=E5=8F=A3=E7=9A=84=E6=8E=A5=E6=94=B6=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=20(#11931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 仅在最后一个使用者关闭串口时清理接收回调。 --- components/drivers/serial/dev_serial.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/drivers/serial/dev_serial.c b/components/drivers/serial/dev_serial.c index e92bcf9e1f..2b020c8306 100644 --- a/components/drivers/serial/dev_serial.c +++ b/components/drivers/serial/dev_serial.c @@ -117,9 +117,17 @@ static int serial_fops_close(struct dfs_file *fd) device = (rt_device_t)fd->vnode->data; - rt_device_set_rx_indicate(device, RT_NULL); + /* close this file descriptor, but only drop the rx indication callback when + * the device is really released. The callback wakes readers (see + * serial_fops_rx_ind), so clearing it while another user still holds the + * device would make that user stop receiving input. */ rt_device_close(device); + if (device->ref_count == 0) + { + rt_device_set_rx_indicate(device, RT_NULL); + } + return 0; }