Commit 90f6e41c authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Doug Ledford

RDMA/uverbs: Use kernel API to allocate uverbs indexes

Replace custom code to allocate indexes to generic kernel API.
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 7d65cbf0
...@@ -73,7 +73,7 @@ enum { ...@@ -73,7 +73,7 @@ enum {
static dev_t dynamic_uverbs_dev; static dev_t dynamic_uverbs_dev;
static struct class *uverbs_class; static struct class *uverbs_class;
static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); static DEFINE_IDA(uverbs_ida);
static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
const char __user *buf, int in_len, const char __user *buf, int in_len,
...@@ -1268,11 +1268,11 @@ static void ib_uverbs_add_one(struct ib_device *device) ...@@ -1268,11 +1268,11 @@ static void ib_uverbs_add_one(struct ib_device *device)
rcu_assign_pointer(uverbs_dev->ib_dev, device); rcu_assign_pointer(uverbs_dev->ib_dev, device);
uverbs_dev->num_comp_vectors = device->num_comp_vectors; uverbs_dev->num_comp_vectors = device->num_comp_vectors;
devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES); devnum = ida_alloc_max(&uverbs_ida, IB_UVERBS_MAX_DEVICES - 1,
if (devnum >= IB_UVERBS_MAX_DEVICES) GFP_KERNEL);
if (devnum < 0)
goto err; goto err;
uverbs_dev->devnum = devnum; uverbs_dev->devnum = devnum;
set_bit(devnum, dev_map);
if (devnum >= IB_UVERBS_NUM_FIXED_MINOR) if (devnum >= IB_UVERBS_NUM_FIXED_MINOR)
base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR; base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR;
else else
...@@ -1296,7 +1296,7 @@ static void ib_uverbs_add_one(struct ib_device *device) ...@@ -1296,7 +1296,7 @@ static void ib_uverbs_add_one(struct ib_device *device)
return; return;
err_uapi: err_uapi:
clear_bit(devnum, dev_map); ida_free(&uverbs_ida, devnum);
err: err:
if (atomic_dec_and_test(&uverbs_dev->refcount)) if (atomic_dec_and_test(&uverbs_dev->refcount))
ib_uverbs_comp_dev(uverbs_dev); ib_uverbs_comp_dev(uverbs_dev);
...@@ -1371,7 +1371,7 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data) ...@@ -1371,7 +1371,7 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data)
return; return;
cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev); cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev);
clear_bit(uverbs_dev->devnum, dev_map); ida_free(&uverbs_ida, uverbs_dev->devnum);
if (device->disassociate_ucontext) { if (device->disassociate_ucontext) {
/* We disassociate HW resources and immediately return. /* We disassociate HW resources and immediately return.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment