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 2022/11/11 12:04:42 UTC
[incubator-nuttx] 02/02: rptun: fix race-condition on g_rptun_cb & g_rptun_priv
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
commit 8aa51452739ef1b2364841ce6b68e83614b23170
Author: ligd <li...@xiaomi.com>
AuthorDate: Mon Oct 31 23:40:16 2022 +0800
rptun: fix race-condition on g_rptun_cb & g_rptun_priv
both rptun_dev_start() & rpmsg_register_callback() will use
these two lists
Signed-off-by: ligd <li...@xiaomi.com>
---
drivers/rptun/rptun.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 8cdbc92109..e7b49740ca 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -196,8 +196,7 @@ static const struct image_store_ops g_rptun_storeops =
static METAL_DECLARE_LIST(g_rptun_cb);
static METAL_DECLARE_LIST(g_rptun_priv);
-static rmutex_t g_rptun_lockcb = NXRMUTEX_INITIALIZER;
-static rmutex_t g_rptun_lockpriv = NXRMUTEX_INITIALIZER;
+static rmutex_t g_rptun_lockcb = NXRMUTEX_INITIALIZER;
/****************************************************************************
* Private Functions
@@ -746,13 +745,10 @@ static int rptun_dev_start(FAR struct remoteproc *rproc)
}
}
- nxrmutex_unlock(&g_rptun_lockcb);
-
/* Add priv to list */
- nxrmutex_lock(&g_rptun_lockpriv);
metal_list_add_tail(&g_rptun_priv, &priv->node);
- nxrmutex_unlock(&g_rptun_lockpriv);
+ nxrmutex_unlock(&g_rptun_lockcb);
virtqueue_enable_cb(priv->rvdev.svq);
@@ -778,14 +774,11 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc)
/* Remove priv from list */
- nxrmutex_lock(&g_rptun_lockpriv);
+ nxrmutex_lock(&g_rptun_lockcb);
metal_list_del(&priv->node);
- nxrmutex_unlock(&g_rptun_lockpriv);
/* Broadcast device_destroy to all registers */
- nxrmutex_lock(&g_rptun_lockcb);
-
metal_list_for_each(&g_rptun_cb, node)
{
cb = metal_container_of(node, struct rptun_cb_s, node);
@@ -1075,7 +1068,7 @@ int rpmsg_register_callback(FAR void *priv_,
cb->ns_match = ns_match;
cb->ns_bind = ns_bind;
- nxrmutex_lock(&g_rptun_lockpriv);
+ nxrmutex_lock(&g_rptun_lockcb);
metal_list_for_each(&g_rptun_priv, node)
{
@@ -1115,9 +1108,6 @@ again:
nxrmutex_unlock(&priv->lock);
}
- nxrmutex_unlock(&g_rptun_lockpriv);
-
- nxrmutex_lock(&g_rptun_lockcb);
metal_list_add_tail(&g_rptun_cb, &cb->node);
nxrmutex_unlock(&g_rptun_lockcb);
@@ -1153,12 +1143,8 @@ void rpmsg_unregister_callback(FAR void *priv_,
}
}
- nxrmutex_unlock(&g_rptun_lockcb);
-
if (device_destroy)
{
- nxrmutex_lock(&g_rptun_lockpriv);
-
metal_list_for_each(&g_rptun_priv, pnode)
{
struct rptun_priv_s *priv;
@@ -1167,9 +1153,9 @@ void rpmsg_unregister_callback(FAR void *priv_,
struct rptun_priv_s, node);
device_destroy(&priv->rvdev.rdev, priv_);
}
-
- nxrmutex_unlock(&g_rptun_lockpriv);
}
+
+ nxrmutex_unlock(&g_rptun_lockcb);
}
int rptun_initialize(FAR struct rptun_dev_s *dev)