drivers/serial: fix the issue of the refs count for filep being zeroed out by utilizing dup2

file_open will clear filep, include f_refs

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2025-06-24 21:40:02 +08:00 committed by Alan C. Assis
parent e85cdac2ed
commit 224dc48a95

View file

@ -206,12 +206,10 @@ static int ptmx_open(FAR struct file *filep)
/* Open the master device: /dev/ptyN, where N=minor */
snprintf(devname, sizeof(devname), "/dev/pty%d", minor);
memcpy(&temp, filep, sizeof(temp));
ret = file_open(filep, devname, O_RDWR | O_CLOEXEC);
ret = file_open(&temp, devname, O_RDWR | O_CLOEXEC);
DEBUGASSERT(ret >= 0); /* file_open() should never fail */
/* Close the multiplexor device: /dev/ptmx */
ret = file_dup2(&temp, filep);
DEBUGASSERT(ret >= 0); /* file_dup2() should never fail) */
ret = file_close(&temp);
DEBUGASSERT(ret >= 0); /* file_close() should never fail */