mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
nuttx/drivers: add ept_release_cb for destroy server resource
use ept_release_cb to destory rpmsg services server dile resource to avoid the used-after-free issue Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
@@ -135,7 +135,6 @@ static void regulator_rpmsg_client_created(struct rpmsg_device *rdev,
|
||||
static void regulator_rpmsg_client_destroy(struct rpmsg_device *rdev,
|
||||
FAR void *priv);
|
||||
|
||||
static void regulator_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static bool regulator_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
@@ -330,7 +329,16 @@ static void regulator_rpmsg_client_destroy(struct rpmsg_device *rdev,
|
||||
}
|
||||
}
|
||||
|
||||
static void regulator_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static bool regulator_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
return strcmp(name, REGULATOR_RPMSG_EPT_NAME) == 0;
|
||||
}
|
||||
|
||||
static void
|
||||
regulator_rpmsg_server_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct regulator_rpmsg_server_s *server = ept->priv;
|
||||
FAR struct regulator_rpmsg_s *reg;
|
||||
@@ -350,18 +358,9 @@ static void regulator_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
}
|
||||
|
||||
nxmutex_destroy(&server->lock);
|
||||
rpmsg_destroy_ept(ept);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
static bool regulator_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
return strcmp(name, REGULATOR_RPMSG_EPT_NAME) == 0;
|
||||
}
|
||||
|
||||
static void regulator_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
@@ -376,13 +375,14 @@ static void regulator_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
}
|
||||
|
||||
server->ept.priv = server;
|
||||
server->ept.release_cb = regulator_rpmsg_server_ept_release;
|
||||
nxmutex_init(&server->lock);
|
||||
list_initialize(&server->regulator_list);
|
||||
|
||||
rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
regulator_rpmsg_ept_cb,
|
||||
regulator_rpmsg_server_unbind);
|
||||
rpmsg_destroy_ept);
|
||||
}
|
||||
|
||||
static int regulator_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
|
||||
Reference in New Issue
Block a user