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

commit 535ca3a414668698887e924299abb472f43121f1
Author: wangshaoxin <[email protected]>
AuthorDate: Mon Aug 31 19:02:33 2026 +0800

    drivers/syslog: keep the partial rpmsg line in a fixed buffer
    
    syslog_rpmsg_ept_cb() kept the unterminated tail of each transfer in a
    buffer that it grew with kmm_realloc() from the endpoint callback, and
    cut the tail only when the allocation failed.
    
    Keep the tail in a SYSLOG_RPMSG_MAXLEN buffer inside struct
    syslog_rpmsg_server_s instead, so the callback never allocates.  The
    part of a partial line that does not fit is dropped.
    syslog_rpmsg_write_internal() could merge at most SYSLOG_RPMSG_MAXLEN
    bytes with the rest of the line anyway.
    
    Signed-off-by: wangshaoxin <[email protected]>
---
 drivers/syslog/syslog_rpmsg_server.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/drivers/syslog/syslog_rpmsg_server.c 
b/drivers/syslog/syslog_rpmsg_server.c
index 9143bd51f05..72d767f232f 100644
--- a/drivers/syslog/syslog_rpmsg_server.c
+++ b/drivers/syslog/syslog_rpmsg_server.c
@@ -54,9 +54,8 @@ struct syslog_rpmsg_server_s
   struct list_node      node;
 #endif
   struct rpmsg_endpoint ept;
-  FAR char              *tmpbuf;
+  char                  tmpbuf[SYSLOG_RPMSG_MAXLEN];
   unsigned int          nextpos;
-  unsigned int          alloced;
 };
 
 /****************************************************************************
@@ -188,7 +187,6 @@ static void syslog_rpmsg_ept_release(FAR struct 
rpmsg_endpoint *ept)
   nxmutex_unlock(&g_lock);
 #endif
 
-  kmm_free(priv->tmpbuf);
   kmm_free(priv);
 }
 
@@ -259,18 +257,12 @@ static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint 
*ept,
       if (copied != 0)
         {
           unsigned int newsize = priv->nextpos + copied;
-          if (newsize > priv->alloced)
+
+          /* tmpbuf does not grow: drop the part that does not fit */
+
+          if (newsize > SYSLOG_RPMSG_MAXLEN)
             {
-              FAR char *newbuf = kmm_realloc(priv->tmpbuf, newsize);
-              if (newbuf != NULL)
-                {
-                  priv->tmpbuf  = newbuf;
-                  priv->alloced = newsize;
-                }
-              else
-                {
-                  copied = priv->alloced - priv->nextpos;
-                }
+              copied = SYSLOG_RPMSG_MAXLEN - priv->nextpos;
             }
 
           memcpy(priv->tmpbuf + priv->nextpos, msg->data + printed, copied);

Reply via email to