This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new bf6adc6cedb drivers/serial: extend open_count to uint16_t type in 
uart_dev_s
bf6adc6cedb is described below

commit bf6adc6cedbebc18e5166eaea903196ee42242d3
Author: fangpeina <[email protected]>
AuthorDate: Mon Jan 20 21:09:12 2025 +0800

    drivers/serial: extend open_count to uint16_t type in uart_dev_s
    
    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]>
---
 drivers/serial/serial.c       | 4 ++--
 include/nuttx/serial/serial.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index f2da3679419..12fdfaa183b 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -900,7 +900,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.
@@ -935,7 +935,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;
diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h
index 65877653176..563d05eb0cd 100644
--- a/include/nuttx/serial/serial.h
+++ b/include/nuttx/serial/serial.h
@@ -325,7 +325,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;       /* VT100/ANSI escape sequence echo-
                                        * suppression state (see the
                                        * UART_ESCAPE_* values used in

Reply via email to