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 ca8d207ada7860a6fc6a6b3eb22ac780c50ab307
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Nov 24 17:04:35 2026 +0800

    drivers/rpmsg/rpmsg_port: reuse the common name service handling
    
    The name service handling in rpmsg_port_ns_callback() is a copy of
    what openamp now provides as rpmsg_ns_handle_msg(), and behaves the same
    since the previous commit. Drop the copy and call the common one. Only
    the transport specific part stays: copying the message out of the
    receive buffer and releasing that buffer before any user callback runs.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg_port.c | 121 +--------------------------------------------
 1 file changed, 1 insertion(+), 120 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_port.c b/drivers/rpmsg/rpmsg_port.c
index 550edabd584..2b3feae980f 100644
--- a/drivers/rpmsg/rpmsg_port.c
+++ b/drivers/rpmsg/rpmsg_port.c
@@ -494,9 +494,6 @@ 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;
   struct rpmsg_ns_msg msg;
-  FAR const char *name;
-  uint32_t dest;
-  bool ept_to_release;
 
   if (len != sizeof(msg))
     {
@@ -510,123 +507,7 @@ static int rpmsg_port_ns_callback(FAR struct 
rpmsg_endpoint *ept,
   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 the ept release callback is not implemented, the callbacks below
-   * can free the endpoint. Test ept->release_cb before relying on the
-   * endpoint staying alive across them.
-   */
-
-  ept_to_release = ept != NULL && ept->release_cb != NULL;
-
-  if (msg.flags == RPMSG_NS_DESTROY)
-    {
-      if (ept != NULL)
-        {
-          ept->dest_addr = RPMSG_ADDR_ANY;
-        }
-
-      if (ept_to_release)
-        {
-          rpmsg_ept_incref(ept);
-        }
-
-      metal_mutex_release(&rdev->lock);
-      if (ept != NULL && ept->ns_unbind_cb != NULL)
-        {
-          ept->ns_unbind_cb(ept);
-        }
-
-      if (rdev->ns_unbind_cb != NULL)
-        {
-          rdev->ns_unbind_cb(rdev, name, dest);
-        }
-
-      if (ept_to_release)
-        {
-          metal_mutex_acquire(&rdev->lock);
-          rpmsg_ept_decref(ept);
-          metal_mutex_release(&rdev->lock);
-        }
-    }
-  else if (msg.flags == RPMSG_NS_CREATE)
-    {
-      if (ept == NULL)
-        {
-          metal_mutex_release(&rdev->lock);
-          if (rdev->ns_bind_cb != NULL)
-            {
-              rdev->ns_bind_cb(rdev, name, dest);
-            }
-        }
-      else if (ept->dest_addr == RPMSG_ADDR_ANY)
-        {
-          ept->dest_addr = dest;
-          if (ept_to_release)
-            {
-              rpmsg_ept_incref(ept);
-            }
-
-          metal_mutex_release(&rdev->lock);
-          if (ept->name[0] && rdev->support_ack)
-            {
-              rpmsg_send_ns_message(ept, RPMSG_NS_CREATE_ACK);
-            }
-
-          /* Notify application that the endpoint has been bound */
-
-          if (ept->ns_bound_cb != NULL)
-            {
-              ept->ns_bound_cb(ept);
-            }
-
-          if (ept_to_release)
-            {
-              metal_mutex_acquire(&rdev->lock);
-              rpmsg_ept_decref(ept);
-              metal_mutex_release(&rdev->lock);
-            }
-        }
-      else
-        {
-          metal_mutex_release(&rdev->lock);
-        }
-    }
-  else
-    {
-      /* RPMSG_NS_CREATE_ACK */
-
-      if (ept != NULL && ept->dest_addr == RPMSG_ADDR_ANY)
-        {
-          ept->dest_addr = dest;
-          if (ept_to_release)
-            {
-              rpmsg_ept_incref(ept);
-            }
-
-          metal_mutex_release(&rdev->lock);
-
-          if (ept->ns_bound_cb != NULL)
-            {
-              ept->ns_bound_cb(ept);
-            }
-
-          if (ept_to_release)
-            {
-              metal_mutex_acquire(&rdev->lock);
-              rpmsg_ept_decref(ept);
-              metal_mutex_release(&rdev->lock);
-            }
-        }
-      else
-        {
-          metal_mutex_release(&rdev->lock);
-        }
-    }
+  rpmsg_ns_handle_msg(rdev, &msg);
 
   return RPMSG_SUCCESS_BUFFER_RELEASED;
 }

Reply via email to