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 189bbe5e5c824dbc119d5c80f90c278bec028362 Author: wangshaoxin <[email protected]> AuthorDate: Thu Nov 12 18:52:07 2026 +0800 net/rpmsg: allocate the socket name suffix atomically g_rpmsg_id++ is a non-atomic read-modify-write, so two threads that connect at the same time can get the same suffix and create two endpoints with the same name. Name service messages are matched by name, so the peer may drop or misroute one of them. Use atomic_add(). Signed-off-by: wangshaoxin <[email protected]> --- net/rpmsg/rpmsg_sockif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index fbe0e37a236..76a2630f08a 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -251,7 +251,7 @@ const struct sock_intf_s g_rpmsg_sockif = * Private Data ****************************************************************************/ -static uint32_t g_rpmsg_id; +static atomic_t g_rpmsg_id; /* Listening sockets. rpmsg_socket_ns_bind() holds the lock while it uses * the server it found, so that close() cannot free that server meanwhile. @@ -1021,7 +1021,7 @@ static int rpmsg_socket_setaddr(FAR struct rpmsg_socket_conn_s *conn, if (suffix) { snprintf(conn->nameid, sizeof(conn->nameid), ":%" PRIx32, - g_rpmsg_id++); + atomic_add(&g_rpmsg_id, 1)); } else {
