summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
author陈泽堂 <[email protected]>2026-11-05 11:16:53 +0800
committerGitHub <[email protected]>2026-11-05 11:16:53 +0800
commit0aae54ae977860d0f17f6312d078ae39fa8c324d (patch)
tree63e984b02b58dbaf13c5f4085a767532c67d2adf /components/drivers
parentd42ffde1b58b186e2c91f201dab1b2df387fc00c (diff)
[drivers][serial] 保留共享串口的接收回调 (#11931)
仅在最后一个使用者关闭串口时清理接收回调。
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/serial/dev_serial.c10
1 files changed, 9 insertions, 1 deletions
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;
}