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

jerpelea 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 d2109c20d2a drivers/rpmsg/rpmsg_port: release the rx buffer early in 
the ns callback
d2109c20d2a is described below

commit d2109c20d2af03dd410b576fa5aab1a8212fbf9e
Author: Bowen Wang <[email protected]>
AuthorDate: Fri Jun 26 17:09:01 2026 +0800

    drivers/rpmsg/rpmsg_port: release the rx buffer early in the ns callback
    
    rpmsg_port_ns_callback() parses the name service message in place, so
    the rx buffer stays held across the bind, unbind and bound callbacks of
    the application. Like the rpmsg_virtio name service path, copy the
    message to a local variable, release the rx buffer right away and
    return RPMSG_SUCCESS_BUFFER_RELEASED so that rpmsg_port_rx_callback()
    does not release it a second time. This frees the rx buffer for new
    frames while the callbacks run.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c
index 502cdedab73..5c9acb557ec 100644
--- a/drivers/rpmsg/rpmsg_port.c
+++ b/drivers/rpmsg/rpmsg_port.c
@@ -481,20 +481,30 @@ static int rpmsg_port_ns_callback(FAR struct 
rpmsg_endpoint *ept,
 {
   FAR struct rpmsg_port_s *port = priv;
   FAR struct rpmsg_device *rdev = &port->rdev;
-  FAR struct rpmsg_ns_msg *msg = data;
-  FAR const char *name = msg->name;
-  uint32_t dest = msg->addr;
+  struct rpmsg_ns_msg msg;
+  FAR const char *name;
+  uint32_t dest;
   bool decref = false;
 
-  if (len != sizeof(*msg))
+  if (len != sizeof(msg))
     {
       return RPMSG_SUCCESS;
     }
 
+  /* Copy buffer to local message and release the rx buffer early to
+   * improve the buffer utilization.
+   */
+
+  memcpy(&msg, data, sizeof(msg));
+  rpmsg_port_release_rx_buffer(rdev, data);
+
+  name = msg.name;
+  dest = msg.addr;
+
   metal_mutex_acquire(&rdev->lock);
   ept = rpmsg_get_endpoint(rdev, name, RPMSG_ADDR_ANY, dest);
 
-  if (msg->flags == RPMSG_NS_DESTROY)
+  if (msg.flags == RPMSG_NS_DESTROY)
     {
       if (ept != NULL)
         {
@@ -524,7 +534,7 @@ static int rpmsg_port_ns_callback(FAR struct rpmsg_endpoint 
*ept,
           metal_mutex_release(&rdev->lock);
         }
     }
-  else if (msg->flags == RPMSG_NS_CREATE)
+  else if (msg.flags == RPMSG_NS_CREATE)
     {
       if (ept == NULL)
         {
@@ -575,7 +585,7 @@ static int rpmsg_port_ns_callback(FAR struct rpmsg_endpoint 
*ept,
         }
     }
 
-  return RPMSG_SUCCESS;
+  return RPMSG_SUCCESS_BUFFER_RELEASED;
 }
 
 /****************************************************************************

Reply via email to