mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 17:48:54 +08:00
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:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user