Skip to content

Commit

Permalink
drivers/serial: extend open_count to uint16_t type in uart_dev_s
Browse files Browse the repository at this point in the history
Fix file duplicaion failure(-24) for /dev/console,
when may tasks(more than 85) exist.

ap> cu -l /dev/ttyCP
[01/19 06:48:44] [13] [ap] files_duplist: Dup fd 0
[01/19 06:48:44] [13] [ap] 13  0   3       1    0         /dev/console
[01/19 06:48:44] [13] [ap] files_duplist: Dup fd 1
[01/19 06:48:44] [13] [ap] 13  0   3       1    0         /dev/console
[01/19 06:48:44] [13] [ap] files_duplist: file_dup2 failed ret -24 line 765
[01/19 06:48:44] [13] [ap] files_duplist: file_dup2 failed  line 769
[01/19 06:48:44] [1036] [ap] PID FD  FLAGS   TYPE POS       PATH
[01/19 06:48:44] [1036] [ap] 10360   3       1    0         /dev/console
[01/19 06:48:44] [1036] [ap] PID FD  FLAGS   TYPE POS       PATH
[01/19 06:48:44] [1036] [ap] 10360   3       1    0         /dev/console
[01/19 06:48:44] [1036] [ap] 10361   3       1    0         /dev/ttyCP

Signed-off-by: fangpeina <[email protected]>
  • Loading branch information
fangpeina committed Feb 27, 2025
1 parent 4c37e27 commit fb97136
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions drivers/serial/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static int uart_open(FAR struct file *filep)
{
FAR struct inode *inode = filep->f_inode;
FAR uart_dev_t *dev = inode->i_private;
uint8_t tmp;
uint16_t tmp;
int ret;

/* If the port is the middle of closing, wait until the close is finished.
Expand Down Expand Up @@ -686,7 +686,7 @@ static int uart_open(FAR struct file *filep)
tmp = dev->open_count + 1;
if (tmp == 0)
{
/* More than 255 opens; uint8_t overflows to zero */
/* More than 65535 opens; uint16_t overflows to zero */

ret = -EMFILE;
goto errout_with_lock;
Expand Down
2 changes: 1 addition & 1 deletion include/nuttx/serial/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ struct uart_dev_s
{
/* State data */

uint8_t open_count; /* Number of times the device has been opened */
uint16_t open_count; /* Number of times the device has been opened */
uint8_t escape; /* Number of the character to be escaped */
#ifdef CONFIG_SERIAL_REMOVABLE
volatile bool disconnected; /* true: Removable device is not connected */
Expand Down

0 comments on commit fb97136

Please sign in to comment.