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 <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-10-31 23:40:16 +08:00 committed by Xiang Xiao
parent f599527e1e
commit 8aa5145273

View File

@ -197,7 +197,6 @@ 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;
/****************************************************************************
* 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)