You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/07/04 11:23:14 UTC

[incubator-nuttx] branch master updated: rpmsg_socket: fix rpmsg_socket_device_destroy() multi-access

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

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new b83b974  rpmsg_socket: fix rpmsg_socket_device_destroy() multi-access
b83b974 is described below

commit b83b974e924403b3ea0c5720f3a0ebd39e2f4dee
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Mar 17 14:34:22 2021 +0800

    rpmsg_socket: fix rpmsg_socket_device_destroy() multi-access
    
    Reason:
    When user call rpmsg_socket_close() at the same time
    rpmsg_socket_ns_unbind() is called by remote CPU,
    then will meet multi-access to rpmsg_socket_device_destroy()
    
    Fix:
    reuse recvlock to handle this
    
    Change-Id: I8f33658f19c56a4000382ff9355ff052c45afea0
    Signed-off-by: ligd <li...@xiaomi.com>
---
 net/rpmsg/rpmsg_sockif.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c
index 9fb961f..33ebd75 100644
--- a/net/rpmsg/rpmsg_sockif.c
+++ b/net/rpmsg/rpmsg_sockif.c
@@ -386,7 +386,14 @@ static int rpmsg_socket_ept_cb(FAR struct rpmsg_endpoint *ept,
 static inline void rpmsg_socket_destroy_ept(
                     FAR struct rpmsg_socket_conn_s *conn)
 {
-  if (conn && conn->ept.rdev)
+  if (!conn)
+    {
+      return;
+    }
+
+  rpmsg_socket_lock(&conn->recvlock);
+
+  if (conn->ept.rdev)
     {
       if (conn->backlog)
         {
@@ -400,6 +407,8 @@ static inline void rpmsg_socket_destroy_ept(
       rpmsg_socket_post(&conn->recvsem);
       rpmsg_socket_pollnotify(conn, POLLIN | POLLOUT);
     }
+
+  rpmsg_socket_unlock(&conn->recvlock);
 }
 
 static void rpmsg_socket_ns_unbind(FAR struct rpmsg_endpoint *ept)