mirror of
https://github.com/apache/nuttx.git
synced 2026-03-27 02:29:15 +08:00
rpmsg: call unbound_cb if service used as server/client when it is destroyed
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Before this patch, the rpmsg services will not be destroied after call the rpmsg_device_destory(). And will cause error after call rpmsg_device_created() at the secound connecting witt peer. Signed-off-by: liaoao <liaoao@xiaomi.com> Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This commit is contained in:
@@ -232,6 +232,7 @@ int rpmsg_register_callback(FAR void *priv,
|
||||
cb->ns_bind = ns_bind;
|
||||
|
||||
nxrmutex_lock(&g_rpmsg_lock);
|
||||
metal_list_add_tail(&g_rpmsg_cb, &cb->node);
|
||||
metal_list_for_each(&g_rpmsg, node)
|
||||
{
|
||||
FAR struct rpmsg_s *rpmsg =
|
||||
@@ -275,7 +276,6 @@ again:
|
||||
nxrmutex_unlock(&rpmsg->lock);
|
||||
}
|
||||
|
||||
metal_list_add_tail(&g_rpmsg_cb, &cb->node);
|
||||
nxrmutex_unlock(&g_rpmsg_lock);
|
||||
|
||||
return 0;
|
||||
@@ -418,6 +418,7 @@ void rpmsg_device_destory(FAR struct rpmsg_s *rpmsg)
|
||||
{
|
||||
FAR struct metal_list *node;
|
||||
FAR struct metal_list *tmp;
|
||||
FAR struct rpmsg_endpoint *ept;
|
||||
|
||||
#ifdef CONFIG_RPMSG_PING
|
||||
rpmsg_ping_deinit(&rpmsg->ping);
|
||||
@@ -450,6 +451,24 @@ void rpmsg_device_destory(FAR struct rpmsg_s *rpmsg)
|
||||
}
|
||||
|
||||
nxrmutex_unlock(&g_rpmsg_lock);
|
||||
|
||||
/* Release all ept attached to current rpmsg device */
|
||||
|
||||
metal_mutex_acquire(&rpmsg->rdev->lock);
|
||||
metal_list_for_each_safe(&rpmsg->rdev->endpoints, tmp, node)
|
||||
{
|
||||
ept = metal_container_of(node, struct rpmsg_endpoint, node);
|
||||
if (ept->ns_unbind_cb)
|
||||
{
|
||||
ept->ns_unbind_cb(ept);
|
||||
}
|
||||
else
|
||||
{
|
||||
rpmsg_destroy_ept(ept);
|
||||
}
|
||||
}
|
||||
|
||||
metal_mutex_release(&rpmsg->rdev->lock);
|
||||
}
|
||||
|
||||
int rpmsg_register(FAR const char *path, FAR struct rpmsg_s *rpmsg,
|
||||
|
||||
@@ -612,9 +612,6 @@ int rpmsg_port_initialize(FAR struct rpmsg_port_s *port,
|
||||
rdev->support_ack = true;
|
||||
rdev->support_ns = true;
|
||||
|
||||
rpmsg_register_endpoint(rdev, &rdev->ns_ept, "NS", RPMSG_NS_EPT_ADDR,
|
||||
RPMSG_NS_EPT_ADDR, rpmsg_port_ns_callback, NULL,
|
||||
port);
|
||||
port->ops->register_callback(port, rpmsg_port_rx_callback);
|
||||
|
||||
return 0;
|
||||
@@ -626,22 +623,9 @@ int rpmsg_port_initialize(FAR struct rpmsg_port_s *port,
|
||||
|
||||
void rpmsg_port_uninitialize(FAR struct rpmsg_port_s *port)
|
||||
{
|
||||
FAR struct rpmsg_device *rdev = &port->rdev;
|
||||
FAR struct metal_list *node;
|
||||
FAR struct rpmsg_endpoint *ept;
|
||||
FAR struct rpmsg_s *rpmsg = &port->rpmsg;
|
||||
|
||||
while (!metal_list_is_empty(&rdev->endpoints))
|
||||
{
|
||||
node = rdev->endpoints.next;
|
||||
ept = metal_container_of(node, struct rpmsg_endpoint, node);
|
||||
rpmsg_destroy_ept(ept);
|
||||
if (ept->ns_unbind_cb)
|
||||
{
|
||||
ept->ns_unbind_cb(ept);
|
||||
}
|
||||
}
|
||||
|
||||
metal_mutex_deinit(&rdev->lock);
|
||||
metal_mutex_deinit(&rpmsg->rdev->lock);
|
||||
rpmsg_port_destroy_queues(port);
|
||||
}
|
||||
|
||||
@@ -747,6 +731,9 @@ int rpmsg_port_register(FAR struct rpmsg_port_s *port,
|
||||
return ret;
|
||||
}
|
||||
|
||||
rpmsg_register_endpoint(&port->rdev, &port->rdev.ns_ept, "NS",
|
||||
RPMSG_NS_EPT_ADDR, RPMSG_NS_EPT_ADDR,
|
||||
rpmsg_port_ns_callback, NULL, port);
|
||||
rpmsg_device_created(&port->rpmsg);
|
||||
return ret;
|
||||
}
|
||||
@@ -760,9 +747,9 @@ void rpmsg_port_unregister(FAR struct rpmsg_port_s *port)
|
||||
char name[64];
|
||||
|
||||
snprintf(name, sizeof(name), "/dev/rpmsg/%s", port->cpuname);
|
||||
rpmsg_unregister(name, &port->rpmsg);
|
||||
|
||||
rpmsg_device_destory(&port->rpmsg);
|
||||
rpmsg_unregister(name, &port->rpmsg);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user