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 8e0563b731234e6b9ef49b1df9b0d9bfc9fd9be9
Author: chenzihan1 <[email protected]>
AuthorDate: Wed Jan 7 19:22:35 2026 +0800

    drivers/syslog/syslog_rpmsg: require CONFIG_SYSLOG_RPMSG_BUFSIZE
    
    Point g_syslog_rpmsg at g_sysbuffer statically, instead of on the
    first write, and drop the Kconfig default so that each configuration
    chooses a size. With 0 the driver defines no buffer, and the platform
    must set g_syslog_rpmsg.header (with the size) to a buffer of its own,
    for example one shared with the remote core, before the first message.
    
    Signed-off-by: chenzihan1 <[email protected]>
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/syslog/Kconfig        |  6 ++++--
 drivers/syslog/syslog_rpmsg.c | 34 +++++++++++++++++-----------------
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig
index 79caaf805cb..0d01a98ddf5 100644
--- a/drivers/syslog/Kconfig
+++ b/drivers/syslog/Kconfig
@@ -357,10 +357,12 @@ config SYSLOG_RPMSG
 
 config SYSLOG_RPMSG_BUFSIZE
        int "RPMSG SYSLOG buffer size"
-       default 0
        depends on SYSLOG_RPMSG
        ---help---
-               Size of the console RPMSG syslog.  Default: 0
+               Size of the RPMSG syslog buffer defined by the driver, header
+               included.  With 0, the platform must point g_syslog_rpmsg.header
+               at its own buffer, with the size filled in, before the first
+               message is logged.
 
 config SYSLOG_RPMSG_BUFFER_SECTION
        string "The section where rpmsg syslog buffer is located"
diff --git a/drivers/syslog/syslog_rpmsg.c b/drivers/syslog/syslog_rpmsg.c
index d58f402567b..9fcb69a4c1d 100644
--- a/drivers/syslog/syslog_rpmsg.c
+++ b/drivers/syslog/syslog_rpmsg.c
@@ -82,8 +82,6 @@ static ssize_t syslog_rpmsg_file_write(FAR struct file *filep,
  * Private Data
  ****************************************************************************/
 
-struct syslog_rpmsg_s g_syslog_rpmsg;
-
 #if CONFIG_SYSLOG_RPMSG_BUFSIZE > 0
 #  ifdef SYSLOG_RPMSG_BUFFER_SECTION
 static char g_sysbuffer[CONFIG_SYSLOG_RPMSG_BUFSIZE]
@@ -91,6 +89,17 @@ static char g_sysbuffer[CONFIG_SYSLOG_RPMSG_BUFSIZE]
 #  else
 static char g_sysbuffer[CONFIG_SYSLOG_RPMSG_BUFSIZE];
 #  endif
+
+struct syslog_rpmsg_s g_syslog_rpmsg =
+{
+  .header = (FAR struct syslog_rpmsg_buffer_header_s *)g_sysbuffer,
+  .lock = SP_UNLOCKED,
+};
+#else
+struct syslog_rpmsg_s g_syslog_rpmsg =
+{
+  .lock = SP_UNLOCKED,
+};
 #endif
 
 #ifdef CONFIG_SYSLOG_RPMSG_CHARDEV
@@ -107,33 +116,29 @@ static const struct file_operations g_syslog_rpmsgfops =
  * Private Functions
  ****************************************************************************/
 
-#if CONFIG_SYSLOG_RPMSG_BUFSIZE > 0
 static void syslog_rpmsg_init_buffer(FAR struct syslog_rpmsg_s *priv)
 {
-  FAR struct syslog_rpmsg_buffer_header_s *header =
-    (FAR struct syslog_rpmsg_buffer_header_s *)g_sysbuffer;
+  FAR struct syslog_rpmsg_buffer_header_s *header = priv->header;
   irqstate_t flags;
 
-  if (!priv->header)
-    {
-      priv->header = header;
-      spin_lock_init(&priv->lock);
-    }
+  DEBUGASSERT(priv->header != NULL);
 
   flags = spin_lock_irqsave(&priv->lock);
   if (header->magic != SYSLOG_RPMSG_MAGIC_NUMBER)
     {
       header->head = 0;
       header->tail = 0;
+
+#if CONFIG_SYSLOG_RPMSG_BUFSIZE > 0
       header->size = CONFIG_SYSLOG_RPMSG_BUFSIZE -
-                      sizeof(struct syslog_rpmsg_buffer_header_s);
+                     sizeof(struct syslog_rpmsg_buffer_header_s);
+#endif
 
       header->magic = SYSLOG_RPMSG_MAGIC_NUMBER;
     }
 
   spin_unlock_irqrestore(&priv->lock, flags);
 }
-#endif
 
 static bool syslog_rpmsg_transfer(FAR struct syslog_rpmsg_s *priv, bool wait)
 {
@@ -225,9 +230,7 @@ static void syslog_rpmsg_addbuf(FAR struct syslog_rpmsg_s 
*priv,
       return;
     }
 
-#if CONFIG_SYSLOG_RPMSG_BUFSIZE > 0
   syslog_rpmsg_init_buffer(priv);
-#endif
 
   header = priv->header;
   flags = spin_lock_irqsave(&priv->lock);
@@ -428,10 +431,7 @@ int syslog_rpmsg_init(void)
     }
 #endif
 
-#if CONFIG_SYSLOG_RPMSG_BUFSIZE > 0
   syslog_rpmsg_init_buffer(&g_syslog_rpmsg);
-#endif
-
   return rpmsg_register_callback(&g_syslog_rpmsg,
                                  syslog_rpmsg_device_created,
                                  syslog_rpmsg_device_destroy,

Reply via email to