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 93a85cd94ba drivers/serial: make terminal window size optional for 
DEFAULT_SMALL
93a85cd94ba is described below

commit 93a85cd94ba8ce39e445eb8ae46285a2b42be30f
Author: Swatantra Yadav <[email protected]>
AuthorDate: Sat Nov 21 00:41:15 2026 +0530

    drivers/serial: make terminal window size optional for DEFAULT_SMALL
    
    Add CONFIG_SERIAL_WINSIZE (default !DEFAULT_SMALL) to gate TIOCGWINSZ
    and TIOCSWINSZ ioctl support in the serial and pseudo-terminal drivers.
    When disabled, the struct winsize member is omitted from uart_dev_s and
    pty_devpair_s, and the ioctl cases fall through to the default handler
    returning -ENOTTY.
    
    Saves 288 bytes of Flash and 40 bytes of bss per serial device on
    sim:nsh (x86_64).  On DEFAULT_SMALL ARM targets the struct winsize
    (8 bytes SRAM per UART) is also eliminated.
    
    Assisted-by: Antigravity:claude-opus-4.6
    Signed-off-by: Swatantra Yadav <[email protected]>
---
 Documentation/os/drivers/character/serial.rst | 20 ++++++++++++--------
 drivers/serial/Kconfig                        | 13 +++++++++++++
 drivers/serial/pty.c                          | 10 ++++++++--
 drivers/serial/serial.c                       |  2 ++
 include/nuttx/serial/serial.h                 |  2 ++
 5 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/Documentation/os/drivers/character/serial.rst 
b/Documentation/os/drivers/character/serial.rst
index d57db5c665d..4dedaa1cbaa 100644
--- a/Documentation/os/drivers/character/serial.rst
+++ b/Documentation/os/drivers/character/serial.rst
@@ -70,14 +70,18 @@ Serial Device Drivers
    ID as the process group ID, and ``kill(-pgrp, signo)`` and
    ``killpg()`` send the signal to the process ``pgrp``.
 
--  **Window size**. ``TIOCGWINSZ`` returns the terminal size in a
-   ``struct winsize`` and ``TIOCSWINSZ`` sets it.  The size is 0 rows
-   and 0 columns until a program sets it (for example ``openpty()`` or
-   a remote login server).  A change of the size sends ``SIGWINCH`` to
-   the foreground process group, as above, when ``CONFIG_TTY_SIGINT`` or
-   ``CONFIG_TTY_SIGTSTP`` is enabled.  A pseudo-terminal keeps one size
-   for the master and the slave; the signal goes to the foreground
-   process group of the slave.
+-  **Window size**. With ``CONFIG_SERIAL_WINSIZE``, ``TIOCGWINSZ``
+   returns the terminal size in a ``struct winsize`` and ``TIOCSWINSZ``
+   sets it.  The size is 0 rows and 0 columns until a program sets it
+   (for example ``openpty()`` or a remote login server).  A change of
+   the size sends ``SIGWINCH`` to the foreground process group, as above,
+   when ``CONFIG_TTY_SIGINT`` or ``CONFIG_TTY_SIGTSTP`` is enabled.  A
+   pseudo-terminal keeps one size for the master and the slave; the signal
+   goes to the foreground process group of the slave.  When
+   ``CONFIG_SERIAL_WINSIZE`` is disabled (default on ``DEFAULT_SMALL``),
+   these ioctl calls fail with ``ENOTTY`` (returning -1 and setting
+   ``errno`` to ``ENOTTY``), saving Flash and per-device
+   SRAM.
 
 -  **Serial line break**. When ``CONFIG_SERIAL_BREAK`` is enabled
    (the default except for ``DEFAULT_SMALL``), ``TCSBRK`` and
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index a5bc5210ab5..bb817dc99c4 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -344,6 +344,19 @@ config SERIAL_TERMIOS
                Note: other software settings (echo, \r\n<->\n, break, tcflush)
                are always supported.
 
+config SERIAL_WINSIZE
+       bool "Terminal window size (TIOCGWINSZ/TIOCSWINSZ)"
+       default !DEFAULT_SMALL
+       ---help---
+               Enable TIOCGWINSZ and TIOCSWINSZ ioctl support in the serial
+               and pseudo-terminal drivers.  When enabled, each uart_dev_s
+               carries a struct winsize (8 bytes).  A window size change sends
+               SIGWINCH to the foreground process if CONFIG_TTY_SIGINT or
+               CONFIG_TTY_SIGTSTP is enabled.
+
+               Disable on memory-constrained targets that never resize a
+               terminal to save Flash and per-device SRAM.
+
 config SERIAL_BREAK
        bool "Serial line break (tcsendbreak) support"
        default !DEFAULT_SMALL
diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index bb7f9febae4..b0f727d0c9d 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -118,7 +118,9 @@ struct pty_devpair_s
   bool pp_unlinked;             /* File has been unlinked */
   uint8_t pp_minor;             /* Minor device number */
   uint16_t pp_nopen;            /* Open file count */
+#ifdef CONFIG_SERIAL_WINSIZE
   struct winsize pp_winsize;    /* Window size, same for both ends */
+#endif
   sem_t pp_slavesem;            /* Slave lock semaphore */
   mutex_t pp_lock;              /* Mutual exclusion */
 };
@@ -761,7 +763,8 @@ static int pty_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
   FAR struct inode *inode;
   FAR struct pty_dev_s *dev;
   FAR struct pty_devpair_s *devpair;
-#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
+#if defined(CONFIG_SERIAL_WINSIZE) && \
+    (defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP))
   pid_t winchpid = INVALID_PROCESS_ID;
 #endif
   int ret;
@@ -932,6 +935,7 @@ static int pty_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
         }
         break;
 
+#ifdef CONFIG_SERIAL_WINSIZE
       case TIOCGWINSZ:
         {
           FAR struct winsize *ws = (FAR struct winsize *)arg;
@@ -971,6 +975,7 @@ static int pty_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
             }
         }
         break;
+#endif
 
 #if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
       /* Make the controlling terminal of the calling process */
@@ -1066,7 +1071,8 @@ static int pty_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
   nxmutex_unlock(&devpair->pp_lock);
 
-#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
+#if defined(CONFIG_SERIAL_WINSIZE) && \
+    (defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP))
   /* In a flat build, the signal handler of the caller runs in nxsig_kill()
    * and can use this PTY.
    */
diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index 2d4020875f7..552e2888bfd 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -2093,6 +2093,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
             break;
 #endif
 
+#ifdef CONFIG_SERIAL_WINSIZE
           case TIOCGWINSZ:
             {
               FAR struct winsize *ws = (FAR struct winsize *)(uintptr_t)arg;
@@ -2132,6 +2133,7 @@ static int uart_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
                 }
             }
             break;
+#endif
 
 #if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
           /* Make the controlling terminal of the calling process */
diff --git a/include/nuttx/serial/serial.h b/include/nuttx/serial/serial.h
index bdd237fb036..ff532a183d7 100644
--- a/include/nuttx/serial/serial.h
+++ b/include/nuttx/serial/serial.h
@@ -375,7 +375,9 @@ struct uart_dev_s
 
   /* Terminal window size (TIOCGWINSZ, TIOCSWINSZ) */
 
+#ifdef CONFIG_SERIAL_WINSIZE
   struct winsize       winsize;
+#endif
 
   /* Semaphores & mutex */
 

Reply via email to