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 351248ac4f9 serial: return the actual byte count from 
uart_gdbstub_receive
351248ac4f9 is described below

commit 351248ac4f993234d1c2f911c082bd9085a2b512
Author: anjiahao <[email protected]>
AuthorDate: Thu Nov 26 23:40:14 2026 +0800

    serial: return the actual byte count from uart_gdbstub_receive
    
    The receive loop keeps polling rxavailable() when the port has no
    data, which can spin forever when the requested length is larger than
    what is available, and it returns len even when fewer bytes were read,
    feeding the stub bogus data.  Stop the loop when the port has nothing
    to read and return the actual count.
    
    Signed-off-by: anjiahao <[email protected]>
---
 drivers/serial/serial_gdbstub.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/serial/serial_gdbstub.c b/drivers/serial/serial_gdbstub.c
index 4b4c9c210c1..6fbe4e5e947 100644
--- a/drivers/serial/serial_gdbstub.c
+++ b/drivers/serial/serial_gdbstub.c
@@ -231,22 +231,19 @@ static ssize_t uart_gdbstub_receive(FAR void *priv, FAR 
void *buf,
 
   rxbuf->tail = tail;
 
-  while (i < len)
+  while (i < len && dev->ops->rxavailable(dev))
     {
-      if (dev->ops->rxavailable(dev))
+      if (dev->ops->recvbuf)
         {
-          if (dev->ops->recvbuf)
-            {
-              i += dev->ops->recvbuf(dev, ptr + i, len - i);
-            }
-          else
-            {
-              ptr[i++] = dev->ops->receive(dev, &state);
-            }
+          i += dev->ops->recvbuf(dev, ptr + i, len - i);
+        }
+      else
+        {
+          ptr[i++] = dev->ops->receive(dev, &state);
         }
     }
 
-  return len;
+  return i;
 }
 
 /****************************************************************************

Reply via email to