drivers/rpmsg: fix the race condtion about rpmsg_device_created

xxx_rpmsg_device_created may be called repeatedly.

rptun thread				app thread

rptun_dev_start				xxx_rpmsg_init

...					rpmsg_register_callback
priv->...= rpmsg_ns_unbind;
priv->..= rptun_notify_wait;
					if (ns_unbind_cb)
(switch app thread)				device_created()
						xxx_rpmsg_device_created

					metal_list_add_tail(g_cb);
...
rpmsg_device_created();
	cb->device_created
	xxx_rpmsg_device_created;

Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
yintao
2024-06-14 14:03:15 +08:00
committed by archer
parent 00b6495419
commit 38af7001b6
2 changed files with 4 additions and 2 deletions
+3 -2
View File
@@ -229,7 +229,7 @@ int rpmsg_register_callback(FAR void *priv,
FAR struct rpmsg_s *rpmsg = FAR struct rpmsg_s *rpmsg =
metal_container_of(node, struct rpmsg_s, node); metal_container_of(node, struct rpmsg_s, node);
if (rpmsg->rdev->ns_unbind_cb == NULL) if (!rpmsg->init)
{ {
continue; continue;
} }
@@ -307,7 +307,7 @@ void rpmsg_unregister_callback(FAR void *priv,
FAR struct rpmsg_s *rpmsg = FAR struct rpmsg_s *rpmsg =
metal_container_of(pnode, struct rpmsg_s, node); metal_container_of(pnode, struct rpmsg_s, node);
if (rpmsg->rdev->ns_unbind_cb) if (rpmsg->init)
{ {
device_destroy(rpmsg->rdev, priv); device_destroy(rpmsg->rdev, priv);
} }
@@ -397,6 +397,7 @@ void rpmsg_device_created(FAR struct rpmsg_s *rpmsg)
} }
} }
rpmsg->init = true;
nxrmutex_unlock(&g_rpmsg_lock); nxrmutex_unlock(&g_rpmsg_lock);
#ifdef CONFIG_RPMSG_PING #ifdef CONFIG_RPMSG_PING
+1
View File
@@ -47,6 +47,7 @@
struct rpmsg_s struct rpmsg_s
{ {
bool init;
struct metal_list bind; struct metal_list bind;
rmutex_t lock; rmutex_t lock;
struct metal_list node; struct metal_list node;