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 f5547ff88bfc86a9f64ae2ba7de2580f888f673a
Author: Bowen Wang <[email protected]>
AuthorDate: Thu Sep 11 00:07:39 2025 +0800

    drivers/rpmsg: fix rpmsg_ns_bind() and rpmsg_register_callback()
    
    Fix three problems left by the single exit rework:
    
    - rpmsg_ns_bind() kept walking the callback list after it had dropped
      g_rpmsg_lock and bound the first match. Stop at the first match.
    - rpmsg_ns_bind() only released g_rpmsg_lock when the bind record was
      allocated, so an allocation failure returned with the lock held.
      Release it in both cases.
    - rpmsg_register_callback() set again only once, so the bind list of
      every device after the first was not walked. Set it for each device.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rpmsg/rpmsg.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/rpmsg/rpmsg.c b/drivers/rpmsg/rpmsg.c
index e43ca5090ce..560cffb8d3f 100644
--- a/drivers/rpmsg/rpmsg.c
+++ b/drivers/rpmsg/rpmsg.c
@@ -545,8 +545,8 @@ int rpmsg_register_callback(FAR void *priv,
   FAR struct rpmsg_bind_s *bind;
   FAR struct rpmsg_s *rpmsg;
   FAR struct rpmsg_cb_s *cb;
-  bool again = true;
   int ret = -ENOMEM;
+  bool again;
 
   cb = kmm_zalloc(sizeof(struct rpmsg_cb_s));
   if (cb != NULL)
@@ -581,6 +581,7 @@ int rpmsg_register_callback(FAR void *priv,
 
           DEBUGASSERT(ns_match != NULL);
 
+          again = true;
           nxrmutex_lock(&rpmsg->lock);
           while (again)
             {
@@ -674,6 +675,7 @@ void rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
 
           ns_bind(rdev, cb_priv, name, dest);
           matched = true;
+          break;
         }
     }
 
@@ -688,9 +690,9 @@ void rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
           nxrmutex_lock(&rpmsg->lock);
           list_add_tail(&rpmsg->bind, &bind->node);
           nxrmutex_unlock(&rpmsg->lock);
-
-          up_read(&g_rpmsg_lock);
         }
+
+      up_read(&g_rpmsg_lock);
     }
 }
 

Reply via email to