rpmsg: convert to idr_alloc()
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Ohad Ben-Cohen <ohad@wizery.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
15fc61106a
commit
d0ffce779d
@ -213,13 +213,10 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
|
|||||||
struct rpmsg_channel *rpdev, rpmsg_rx_cb_t cb,
|
struct rpmsg_channel *rpdev, rpmsg_rx_cb_t cb,
|
||||||
void *priv, u32 addr)
|
void *priv, u32 addr)
|
||||||
{
|
{
|
||||||
int err, tmpaddr, request;
|
int id_min, id_max, id;
|
||||||
struct rpmsg_endpoint *ept;
|
struct rpmsg_endpoint *ept;
|
||||||
struct device *dev = rpdev ? &rpdev->dev : &vrp->vdev->dev;
|
struct device *dev = rpdev ? &rpdev->dev : &vrp->vdev->dev;
|
||||||
|
|
||||||
if (!idr_pre_get(&vrp->endpoints, GFP_KERNEL))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
ept = kzalloc(sizeof(*ept), GFP_KERNEL);
|
ept = kzalloc(sizeof(*ept), GFP_KERNEL);
|
||||||
if (!ept) {
|
if (!ept) {
|
||||||
dev_err(dev, "failed to kzalloc a new ept\n");
|
dev_err(dev, "failed to kzalloc a new ept\n");
|
||||||
@ -234,31 +231,28 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
|
|||||||
ept->priv = priv;
|
ept->priv = priv;
|
||||||
|
|
||||||
/* do we need to allocate a local address ? */
|
/* do we need to allocate a local address ? */
|
||||||
request = addr == RPMSG_ADDR_ANY ? RPMSG_RESERVED_ADDRESSES : addr;
|
if (addr == RPMSG_ADDR_ANY) {
|
||||||
|
id_min = RPMSG_RESERVED_ADDRESSES;
|
||||||
|
id_max = 0;
|
||||||
|
} else {
|
||||||
|
id_min = addr;
|
||||||
|
id_max = addr + 1;
|
||||||
|
}
|
||||||
|
|
||||||
mutex_lock(&vrp->endpoints_lock);
|
mutex_lock(&vrp->endpoints_lock);
|
||||||
|
|
||||||
/* bind the endpoint to an rpmsg address (and allocate one if needed) */
|
/* bind the endpoint to an rpmsg address (and allocate one if needed) */
|
||||||
err = idr_get_new_above(&vrp->endpoints, ept, request, &tmpaddr);
|
id = idr_alloc(&vrp->endpoints, ept, id_min, id_max, GFP_KERNEL);
|
||||||
if (err) {
|
if (id < 0) {
|
||||||
dev_err(dev, "idr_get_new_above failed: %d\n", err);
|
dev_err(dev, "idr_alloc failed: %d\n", id);
|
||||||
goto free_ept;
|
goto free_ept;
|
||||||
}
|
}
|
||||||
|
ept->addr = id;
|
||||||
/* make sure the user's address request is fulfilled, if relevant */
|
|
||||||
if (addr != RPMSG_ADDR_ANY && tmpaddr != addr) {
|
|
||||||
dev_err(dev, "address 0x%x already in use\n", addr);
|
|
||||||
goto rem_idr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ept->addr = tmpaddr;
|
|
||||||
|
|
||||||
mutex_unlock(&vrp->endpoints_lock);
|
mutex_unlock(&vrp->endpoints_lock);
|
||||||
|
|
||||||
return ept;
|
return ept;
|
||||||
|
|
||||||
rem_idr:
|
|
||||||
idr_remove(&vrp->endpoints, request);
|
|
||||||
free_ept:
|
free_ept:
|
||||||
mutex_unlock(&vrp->endpoints_lock);
|
mutex_unlock(&vrp->endpoints_lock);
|
||||||
kref_put(&ept->refcount, __ept_release);
|
kref_put(&ept->refcount, __ept_release);
|
||||||
|
Loading…
Reference in New Issue
Block a user