Skip to content

Commit d0ffce7

Browse files
htejuntorvalds
authored andcommitted
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>
1 parent 15fc611 commit d0ffce7

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

‎drivers/rpmsg/virtio_rpmsg_bus.c‎

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,10 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp,
213213
struct rpmsg_channel *rpdev, rpmsg_rx_cb_t cb,
214214
void *priv, u32 addr)
215215
{
216-
int err, tmpaddr, request;
216+
int id_min, id_max, id;
217217
struct rpmsg_endpoint *ept;
218218
struct device *dev = rpdev ? &rpdev->dev : &vrp->vdev->dev;
219219

220-
if (!idr_pre_get(&vrp->endpoints, GFP_KERNEL))
221-
return NULL;
222-
223220
ept = kzalloc(sizeof(*ept), GFP_KERNEL);
224221
if (!ept) {
225222
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,
234231
ept->priv = priv;
235232

236233
/* do we need to allocate a local address ? */
237-
request = addr == RPMSG_ADDR_ANY ? RPMSG_RESERVED_ADDRESSES : addr;
234+
if (addr == RPMSG_ADDR_ANY) {
235+
id_min = RPMSG_RESERVED_ADDRESSES;
236+
id_max = 0;
237+
} else {
238+
id_min = addr;
239+
id_max = addr + 1;
240+
}
238241

239242
mutex_lock(&vrp->endpoints_lock);
240243

241244
/* bind the endpoint to an rpmsg address (and allocate one if needed) */
242-
err = idr_get_new_above(&vrp->endpoints, ept, request, &tmpaddr);
243-
if (err) {
244-
dev_err(dev, "idr_get_new_above failed: %d\n", err);
245+
id = idr_alloc(&vrp->endpoints, ept, id_min, id_max, GFP_KERNEL);
246+
if (id < 0) {
247+
dev_err(dev, "idr_alloc failed: %d\n", id);
245248
goto free_ept;
246249
}
247-
248-
/* make sure the user's address request is fulfilled, if relevant */
249-
if (addr != RPMSG_ADDR_ANY && tmpaddr != addr) {
250-
dev_err(dev, "address 0x%x already in use\n", addr);
251-
goto rem_idr;
252-
}
253-
254-
ept->addr = tmpaddr;
250+
ept->addr = id;
255251

256252
mutex_unlock(&vrp->endpoints_lock);
257253

258254
return ept;
259255

260-
rem_idr:
261-
idr_remove(&vrp->endpoints, request);
262256
free_ept:
263257
mutex_unlock(&vrp->endpoints_lock);
264258
kref_put(&ept->refcount, __ept_release);

0 commit comments

Comments
 (0)