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:
parent
80d03cb296
commit
37a30023f5
13 changed files with 266 additions and 270 deletions
|
@ -166,7 +166,6 @@ static void clk_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
|||
FAR void *priv_,
|
||||
FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void clk_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
|
||||
static int clk_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len,
|
||||
|
@ -514,30 +513,7 @@ static bool clk_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
|||
return !strcmp(name, CLK_RPMSG_EPT_NAME);
|
||||
}
|
||||
|
||||
static void clk_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct clk_rpmsg_server_s *priv;
|
||||
|
||||
priv = kmm_zalloc(sizeof(struct clk_rpmsg_server_s));
|
||||
if (!priv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
priv->ept.priv = priv;
|
||||
|
||||
list_initialize(&priv->clk_list);
|
||||
|
||||
rpmsg_create_ept(&priv->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
clk_rpmsg_ept_cb,
|
||||
clk_rpmsg_server_unbind);
|
||||
}
|
||||
|
||||
static void clk_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static void clk_rpmsg_server_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct clk_rpmsg_server_s *priv = ept->priv;
|
||||
FAR struct clk_rpmsg_s *clkrp_tmp;
|
||||
|
@ -555,11 +531,33 @@ static void clk_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
kmm_free(clkrp);
|
||||
}
|
||||
|
||||
rpmsg_destroy_ept(ept);
|
||||
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
static void clk_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct clk_rpmsg_server_s *priv;
|
||||
|
||||
priv = kmm_zalloc(sizeof(struct clk_rpmsg_server_s));
|
||||
if (!priv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
priv->ept.priv = priv;
|
||||
priv->ept.release_cb = clk_rpmsg_server_ept_release;
|
||||
|
||||
list_initialize(&priv->clk_list);
|
||||
|
||||
rpmsg_create_ept(&priv->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
clk_rpmsg_ept_cb,
|
||||
rpmsg_destroy_ept);
|
||||
}
|
||||
|
||||
static void clk_rpmsg_client_created(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_)
|
||||
{
|
||||
|
|
|
@ -602,13 +602,6 @@ static int ioe_rpmsg_server_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void ioe_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
rpmsg_destroy_ept(ept);
|
||||
|
||||
kmm_free(ept);
|
||||
}
|
||||
|
||||
static bool ioe_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_,
|
||||
FAR const char *name,
|
||||
|
@ -622,6 +615,11 @@ static bool ioe_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
|||
return !strcmp(name, eptname);
|
||||
}
|
||||
|
||||
static void ioe_rpmsg_server_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
kmm_free(ept);
|
||||
}
|
||||
|
||||
static void ioe_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_,
|
||||
FAR const char *name,
|
||||
|
@ -637,9 +635,10 @@ static void ioe_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
ept->priv = priv;
|
||||
ept->release_cb = ioe_rpmsg_server_ept_release;
|
||||
|
||||
rpmsg_create_ept(ept, rdev, name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
ioe_rpmsg_server_ept_cb, ioe_rpmsg_server_unbind);
|
||||
ioe_rpmsg_server_ept_cb, rpmsg_destroy_ept);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -82,7 +82,6 @@ static bool rpmsgblk_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void rpmsgblk_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void rpmsgblk_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int rpmsgblk_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv);
|
||||
|
@ -497,6 +496,18 @@ static bool rpmsgblk_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strncmp(name, RPMSGBLK_NAME_PREFIX, RPMSGBLK_NAME_PREFIX_LEN);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgblk_ept_release
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgblk_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgblk_server_s *server = ept->priv;
|
||||
|
||||
inode_release(server->blknode);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgblk_ns_bind
|
||||
****************************************************************************/
|
||||
|
@ -526,11 +537,12 @@ static void rpmsgblk_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
server->ept.priv = server;
|
||||
server->ept.release_cb = rpmsgblk_ept_release;
|
||||
server->bops = server->blknode->u.i_bops;
|
||||
|
||||
ret = rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgblk_ept_cb, rpmsgblk_ns_unbind);
|
||||
rpmsgblk_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("endpoint create failed, ret=%d\n", ret);
|
||||
|
@ -539,19 +551,6 @@ static void rpmsgblk_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgblk_ns_unbind
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgblk_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgblk_server_s *server = ept->priv;
|
||||
|
||||
rpmsg_destroy_ept(&server->ept);
|
||||
inode_release(server->blknode);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgblk_ept_cb
|
||||
****************************************************************************/
|
||||
|
|
|
@ -112,7 +112,6 @@ static bool rpmsgdev_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void rpmsgdev_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void rpmsgdev_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int rpmsgdev_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv);
|
||||
|
@ -425,41 +424,10 @@ static bool rpmsgdev_ns_match(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgdev_ns_bind
|
||||
* Name: rpmsgdev_ept_release
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgdev_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct rpmsgdev_server_s *server;
|
||||
int ret;
|
||||
|
||||
server = kmm_zalloc(sizeof(*server));
|
||||
if (server == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
list_initialize(&server->head);
|
||||
nxmutex_init(&server->lock);
|
||||
server->ept.priv = server;
|
||||
|
||||
ret = rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgdev_ept_cb, rpmsgdev_ns_unbind);
|
||||
if (ret < 0)
|
||||
{
|
||||
nxmutex_destroy(&server->lock);
|
||||
kmm_free(server);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgdev_ns_unbind
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgdev_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static void rpmsgdev_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgdev_server_s *server = ept->priv;
|
||||
FAR struct rpmsgdev_device_s *dev;
|
||||
|
@ -486,10 +454,41 @@ static void rpmsgdev_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
|
||||
nxmutex_unlock(&server->lock);
|
||||
|
||||
rpmsg_destroy_ept(&server->ept);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgdev_ns_bind
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgdev_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct rpmsgdev_server_s *server;
|
||||
int ret;
|
||||
|
||||
server = kmm_zalloc(sizeof(*server));
|
||||
if (server == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
list_initialize(&server->head);
|
||||
nxmutex_init(&server->lock);
|
||||
server->ept.priv = server;
|
||||
server->ept.release_cb = rpmsgdev_ept_release;
|
||||
|
||||
ret = rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgdev_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret < 0)
|
||||
{
|
||||
nxmutex_destroy(&server->lock);
|
||||
kmm_free(server);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgdev_ept_cb
|
||||
****************************************************************************/
|
||||
|
|
|
@ -85,7 +85,6 @@ static bool rpmsgmtd_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void rpmsgmtd_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void rpmsgmtd_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int rpmsgmtd_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv);
|
||||
|
@ -352,6 +351,18 @@ static bool rpmsgmtd_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strncmp(name, RPMSGMTD_NAME_PREFIX, RPMSGMTD_NAME_PREFIX_LEN);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgmtd_ept_release
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgmtd_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgmtd_server_s *server = ept->priv;
|
||||
|
||||
close_mtddriver(server->mtdnode);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgmtd_ns_bind
|
||||
****************************************************************************/
|
||||
|
@ -379,12 +390,13 @@ static void rpmsgmtd_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
server->ept.priv = server;
|
||||
server->ept.release_cb = rpmsgmtd_ept_release;
|
||||
server->mtdnode = mtdnode;
|
||||
server->dev = mtdnode->u.i_mtd;
|
||||
|
||||
ret = rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgmtd_ept_cb, rpmsgmtd_ns_unbind);
|
||||
rpmsgmtd_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("endpoint create failed, ret=%d\n", ret);
|
||||
|
@ -398,19 +410,6 @@ errout:
|
|||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgmtd_ns_unbind
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsgmtd_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgmtd_server_s *server = ept->priv;
|
||||
|
||||
rpmsg_destroy_ept(&server->ept);
|
||||
close_mtddriver(server->mtdnode);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsgmtd_ept_cb
|
||||
****************************************************************************/
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -678,7 +678,16 @@ static int reset_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void reset_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static bool reset_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
return strcmp(name, RESET_RPMSG_EPT_NAME) == 0;
|
||||
}
|
||||
|
||||
static void reset_rpmsg_server_ept_release(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *priv)
|
||||
{
|
||||
FAR struct reset_rpmsg_server_s *server = ept->priv;
|
||||
FAR struct reset_rpmsg_s *reset;
|
||||
|
@ -692,19 +701,10 @@ static void reset_rpmsg_server_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
kmm_free(reset);
|
||||
}
|
||||
|
||||
rpmsg_destroy_ept(ept);
|
||||
nxmutex_destroy(&server->lock);
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
static bool reset_rpmsg_server_match(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
return strcmp(name, RESET_RPMSG_EPT_NAME) == 0;
|
||||
}
|
||||
|
||||
static void reset_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
|
@ -719,13 +719,14 @@ static void reset_rpmsg_server_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
server->ept.priv = server;
|
||||
server->ept.release_cb = reset_rpmsg_server_ept_release;
|
||||
list_initialize(&server->list);
|
||||
nxmutex_init(&server->lock);
|
||||
|
||||
rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
reset_rpmsg_ept_cb,
|
||||
reset_rpmsg_server_unbind);
|
||||
rpmsg_destroy_ept);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -1311,7 +1311,41 @@ static int sensor_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static void sensor_rpmsg_ns_unbind_cb(FAR struct rpmsg_endpoint *ept)
|
||||
static void sensor_rpmsg_device_ns_bound(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct sensor_rpmsg_ept_s *sre;
|
||||
FAR struct sensor_rpmsg_dev_s *dev;
|
||||
|
||||
sre = container_of(ept, struct sensor_rpmsg_ept_s, ept);
|
||||
|
||||
nxrmutex_lock(&g_ept_lock);
|
||||
list_add_tail(&g_eptlist, &sre->node);
|
||||
nxrmutex_unlock(&g_ept_lock);
|
||||
|
||||
/* Broadcast all device to ready ept */
|
||||
|
||||
nxrmutex_lock(&g_dev_lock);
|
||||
list_for_every_entry(&g_devlist, dev,
|
||||
struct sensor_rpmsg_dev_s, node)
|
||||
{
|
||||
sensor_rpmsg_lock(dev);
|
||||
if (dev->nadvertisers > 0)
|
||||
{
|
||||
sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_ADVERTISE);
|
||||
}
|
||||
|
||||
if (dev->nsubscribers > 0)
|
||||
{
|
||||
sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_SUBSCRIBE);
|
||||
}
|
||||
|
||||
sensor_rpmsg_unlock(dev);
|
||||
}
|
||||
|
||||
nxrmutex_unlock(&g_dev_lock);
|
||||
}
|
||||
|
||||
static void sensor_rpmsg_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct sensor_rpmsg_ept_s *sre;
|
||||
FAR struct sensor_rpmsg_dev_s *dev;
|
||||
|
@ -1363,44 +1397,9 @@ static void sensor_rpmsg_ns_unbind_cb(FAR struct rpmsg_endpoint *ept)
|
|||
nxrmutex_unlock(&g_ept_lock);
|
||||
|
||||
nxrmutex_destroy(&sre->lock);
|
||||
rpmsg_destroy_ept(ept);
|
||||
kmm_free(sre);
|
||||
}
|
||||
|
||||
static void sensor_rpmsg_device_ns_bound(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct sensor_rpmsg_ept_s *sre;
|
||||
FAR struct sensor_rpmsg_dev_s *dev;
|
||||
|
||||
sre = container_of(ept, struct sensor_rpmsg_ept_s, ept);
|
||||
|
||||
nxrmutex_lock(&g_ept_lock);
|
||||
list_add_tail(&g_eptlist, &sre->node);
|
||||
nxrmutex_unlock(&g_ept_lock);
|
||||
|
||||
/* Broadcast all device to ready ept */
|
||||
|
||||
nxrmutex_lock(&g_dev_lock);
|
||||
list_for_every_entry(&g_devlist, dev,
|
||||
struct sensor_rpmsg_dev_s, node)
|
||||
{
|
||||
sensor_rpmsg_lock(dev);
|
||||
if (dev->nadvertisers > 0)
|
||||
{
|
||||
sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_ADVERTISE);
|
||||
}
|
||||
|
||||
if (dev->nsubscribers > 0)
|
||||
{
|
||||
sensor_rpmsg_advsub_one(dev, ept, SENSOR_RPMSG_SUBSCRIBE);
|
||||
}
|
||||
|
||||
sensor_rpmsg_unlock(dev);
|
||||
}
|
||||
|
||||
nxrmutex_unlock(&g_dev_lock);
|
||||
}
|
||||
|
||||
static void sensor_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv)
|
||||
{
|
||||
|
@ -1416,10 +1415,12 @@ static void sensor_rpmsg_device_created(FAR struct rpmsg_device *rdev,
|
|||
sre->ept.priv = sre;
|
||||
nxrmutex_init(&sre->lock);
|
||||
sre->ept.ns_bound_cb = sensor_rpmsg_device_ns_bound;
|
||||
sre->ept.release_cb = sensor_rpmsg_ept_release;
|
||||
|
||||
if (rpmsg_create_ept(&sre->ept, rdev, SENSOR_RPMSG_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, RPMSG_ADDR_ANY,
|
||||
sensor_rpmsg_ept_cb,
|
||||
sensor_rpmsg_ns_unbind_cb) < 0)
|
||||
rpmsg_destroy_ept) < 0)
|
||||
{
|
||||
nxrmutex_destroy(&sre->lock);
|
||||
kmm_free(sre);
|
||||
|
|
|
@ -69,7 +69,6 @@ static bool syslog_rpmsg_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void syslog_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void syslog_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv_);
|
||||
|
@ -171,6 +170,25 @@ static bool syslog_rpmsg_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strcmp(name, SYSLOG_RPMSG_EPT_NAME);
|
||||
}
|
||||
|
||||
static void syslog_rpmsg_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct syslog_rpmsg_server_s *priv = ept->priv;
|
||||
|
||||
if (priv->nextpos)
|
||||
{
|
||||
syslog_rpmsg_write(priv->tmpbuf, priv->nextpos, "\n", 1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
|
||||
nxmutex_lock(&g_lock);
|
||||
list_delete(&priv->node);
|
||||
nxmutex_unlock(&g_lock);
|
||||
#endif
|
||||
|
||||
kmm_free(priv->tmpbuf);
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
static void syslog_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest)
|
||||
|
@ -185,6 +203,7 @@ static void syslog_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
priv->ept.priv = priv;
|
||||
priv->ept.release_cb = syslog_rpmsg_ept_release;
|
||||
|
||||
#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
|
||||
nxmutex_lock(&g_lock);
|
||||
|
@ -194,34 +213,13 @@ static void syslog_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
|
||||
ret = rpmsg_create_ept(&priv->ept, rdev, SYSLOG_RPMSG_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
syslog_rpmsg_ept_cb, syslog_rpmsg_ns_unbind);
|
||||
syslog_rpmsg_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret)
|
||||
{
|
||||
kmm_free(priv);
|
||||
}
|
||||
}
|
||||
|
||||
static void syslog_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct syslog_rpmsg_server_s *priv = ept->priv;
|
||||
|
||||
if (priv->nextpos)
|
||||
{
|
||||
syslog_rpmsg_write(priv->tmpbuf, priv->nextpos, "\n", 1);
|
||||
}
|
||||
|
||||
rpmsg_destroy_ept(ept);
|
||||
|
||||
#ifdef CONFIG_SYSLOG_RPMSG_SERVER_CHARDEV
|
||||
nxmutex_lock(&g_lock);
|
||||
list_delete(&priv->node);
|
||||
nxmutex_unlock(&g_lock);
|
||||
#endif
|
||||
|
||||
kmm_free(priv->tmpbuf);
|
||||
kmm_free(priv);
|
||||
}
|
||||
|
||||
static int syslog_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len,
|
||||
uint32_t src, FAR void *priv_)
|
||||
|
|
|
@ -620,19 +620,6 @@ static int rpmsg_rtc_server_destroy(FAR struct rtc_lowerhalf_s *lower)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void rpmsg_rtc_server_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsg_rtc_client_s *client = container_of(ept,
|
||||
struct rpmsg_rtc_client_s, ept);
|
||||
FAR struct rpmsg_rtc_server_s *server = ept->priv;
|
||||
|
||||
nxmutex_lock(&server->lock);
|
||||
list_delete(&client->node);
|
||||
nxmutex_unlock(&server->lock);
|
||||
rpmsg_destroy_ept(&client->ept);
|
||||
kmm_free(client);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_RTC_ALARM
|
||||
static void rpmsg_rtc_server_alarm_cb(FAR void *priv, int alarmid)
|
||||
{
|
||||
|
@ -720,6 +707,18 @@ static bool rpmsg_rtc_server_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strcmp(name, RPMSG_RTC_EPT_NAME);
|
||||
}
|
||||
|
||||
static void rpmsg_rtc_server_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsg_rtc_client_s *client = container_of(ept,
|
||||
struct rpmsg_rtc_client_s, ept);
|
||||
FAR struct rpmsg_rtc_server_s *server = ept->priv;
|
||||
|
||||
nxmutex_lock(&server->lock);
|
||||
list_delete(&client->node);
|
||||
nxmutex_unlock(&server->lock);
|
||||
kmm_free(client);
|
||||
}
|
||||
|
||||
static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv,
|
||||
FAR const char *name,
|
||||
|
@ -737,10 +736,12 @@ static void rpmsg_rtc_server_ns_bind(FAR struct rpmsg_device *rdev,
|
|||
}
|
||||
|
||||
client->ept.priv = server;
|
||||
client->ept.release_cb = rpmsg_rtc_server_ept_release;
|
||||
|
||||
if (rpmsg_create_ept(&client->ept, rdev, RPMSG_RTC_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsg_rtc_server_ept_cb,
|
||||
rpmsg_rtc_server_ns_unbind) < 0)
|
||||
rpmsg_destroy_ept) < 0)
|
||||
{
|
||||
kmm_free(client);
|
||||
return;
|
||||
|
|
|
@ -153,7 +153,6 @@ static bool usrsock_rpmsg_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void usrsock_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void usrsock_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int usrsock_rpmsg_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv);
|
||||
|
@ -1019,42 +1018,7 @@ static bool usrsock_rpmsg_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strcmp(name, USRSOCK_RPMSG_EPT_NAME);
|
||||
}
|
||||
|
||||
static void usrsock_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct usrsock_rpmsg_s *priv = priv_;
|
||||
FAR struct usrsock_rpmsg_ept_s *uept;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
uept = kmm_zalloc(sizeof(*uept));
|
||||
if (!uept)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uept->ept.priv = priv;
|
||||
for (i = 0; i < CONFIG_NET_USRSOCK_RPMSG_SERVER_NIOVEC; i++)
|
||||
{
|
||||
sq_addlast(&uept->reqs[i].flink, &uept->req_free);
|
||||
}
|
||||
|
||||
ret = rpmsg_create_ept(&uept->ept, rdev, USRSOCK_RPMSG_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
usrsock_rpmsg_ept_cb, usrsock_rpmsg_ns_unbind);
|
||||
if (ret < 0)
|
||||
{
|
||||
kmm_free(uept);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
dns_register_notify(usrsock_rpmsg_send_dns_event, &uept->ept);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void usrsock_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static void usrsock_rpmsg_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct usrsock_rpmsg_s *priv = ept->priv;
|
||||
int i;
|
||||
|
@ -1080,10 +1044,45 @@ static void usrsock_rpmsg_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
}
|
||||
}
|
||||
|
||||
rpmsg_destroy_ept(ept);
|
||||
kmm_free(ept);
|
||||
}
|
||||
|
||||
static void usrsock_rpmsg_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct usrsock_rpmsg_s *priv = priv_;
|
||||
FAR struct usrsock_rpmsg_ept_s *uept;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
uept = kmm_zalloc(sizeof(*uept));
|
||||
if (!uept)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
uept->ept.priv = priv;
|
||||
uept->ept.release_cb = usrsock_rpmsg_ept_release;
|
||||
for (i = 0; i < CONFIG_NET_USRSOCK_RPMSG_SERVER_NIOVEC; i++)
|
||||
{
|
||||
sq_addlast(&uept->reqs[i].flink, &uept->req_free);
|
||||
}
|
||||
|
||||
ret = rpmsg_create_ept(&uept->ept, rdev, USRSOCK_RPMSG_EPT_NAME,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
usrsock_rpmsg_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret < 0)
|
||||
{
|
||||
kmm_free(uept);
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NETDB_DNSCLIENT
|
||||
dns_register_notify(usrsock_rpmsg_send_dns_event, &uept->ept);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int usrsock_rpmsg_ept_do_cb(FAR struct usrsock_rpmsg_ept_s *uept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR struct usrsock_rpmsg_s *priv)
|
||||
|
|
|
@ -399,17 +399,18 @@ static int rpmsghci_ept_cb(FAR struct rpmsg_endpoint *ept, FAR void *data,
|
|||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rpmsghci_ns_unbind
|
||||
* Name: rpmsghci_ept_release
|
||||
*
|
||||
* Description:
|
||||
* Unbind from the rpmsg name service.
|
||||
* Release the rpmsg endpoint.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void rpmsghci_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static void rpmsghci_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
rpmsg_destroy_ept(ept);
|
||||
kmm_free(ept);
|
||||
FAR struct rpmsghci_server_s *server = ept->priv;
|
||||
|
||||
kmm_free(server);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -426,9 +427,11 @@ static void rpmsghci_ns_bind(FAR struct rpmsg_device *rdev, FAR void *priv,
|
|||
FAR struct rpmsghci_server_s *server = priv;
|
||||
|
||||
server->ept.priv = priv;
|
||||
server->ept.release_cb = rpmsghci_ept_release;
|
||||
|
||||
rpmsg_create_ept(&server->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsghci_ept_cb, rpmsghci_ns_unbind);
|
||||
rpmsghci_ept_cb, rpmsg_destroy_ept);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -131,7 +131,6 @@ static bool rpmsgfs_ns_match(FAR struct rpmsg_device *rdev,
|
|||
static void rpmsgfs_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest);
|
||||
static void rpmsgfs_ns_unbind(FAR struct rpmsg_endpoint *ept);
|
||||
static int rpmsgfs_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv);
|
||||
|
@ -888,33 +887,7 @@ static bool rpmsgfs_ns_match(FAR struct rpmsg_device *rdev,
|
|||
return !strncmp(name, RPMSGFS_NAME_PREFIX, strlen(RPMSGFS_NAME_PREFIX));
|
||||
}
|
||||
|
||||
static void rpmsgfs_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct rpmsgfs_server_s *priv;
|
||||
int ret;
|
||||
|
||||
priv = fs_heap_zalloc(sizeof(*priv));
|
||||
if (!priv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
priv->ept.priv = priv;
|
||||
nxmutex_init(&priv->lock);
|
||||
|
||||
ret = rpmsg_create_ept(&priv->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgfs_ept_cb, rpmsgfs_ns_unbind);
|
||||
if (ret)
|
||||
{
|
||||
nxmutex_destroy(&priv->lock);
|
||||
fs_heap_free(priv);
|
||||
}
|
||||
}
|
||||
|
||||
static void rpmsgfs_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
||||
static void rpmsgfs_ept_release(FAR struct rpmsg_endpoint *ept)
|
||||
{
|
||||
FAR struct rpmsgfs_server_s *priv = ept->priv;
|
||||
int i;
|
||||
|
@ -941,7 +914,6 @@ static void rpmsgfs_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
}
|
||||
}
|
||||
|
||||
rpmsg_destroy_ept(&priv->ept);
|
||||
nxmutex_destroy(&priv->lock);
|
||||
|
||||
fs_heap_free(priv->files);
|
||||
|
@ -949,6 +921,33 @@ static void rpmsgfs_ns_unbind(FAR struct rpmsg_endpoint *ept)
|
|||
fs_heap_free(priv);
|
||||
}
|
||||
|
||||
static void rpmsgfs_ns_bind(FAR struct rpmsg_device *rdev,
|
||||
FAR void *priv_, FAR const char *name,
|
||||
uint32_t dest)
|
||||
{
|
||||
FAR struct rpmsgfs_server_s *priv;
|
||||
int ret;
|
||||
|
||||
priv = fs_heap_zalloc(sizeof(*priv));
|
||||
if (!priv)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
priv->ept.priv = priv;
|
||||
priv->ept.release_cb = rpmsgfs_ept_release;
|
||||
nxmutex_init(&priv->lock);
|
||||
|
||||
ret = rpmsg_create_ept(&priv->ept, rdev, name,
|
||||
RPMSG_ADDR_ANY, dest,
|
||||
rpmsgfs_ept_cb, rpmsg_destroy_ept);
|
||||
if (ret)
|
||||
{
|
||||
nxmutex_destroy(&priv->lock);
|
||||
fs_heap_free(priv);
|
||||
}
|
||||
}
|
||||
|
||||
static int rpmsgfs_ept_cb(FAR struct rpmsg_endpoint *ept,
|
||||
FAR void *data, size_t len, uint32_t src,
|
||||
FAR void *priv)
|
||||
|
|
Loading…
Reference in a new issue