diff options
author | Leon Romanovsky <leonro@mellanox.com> | 2018-10-02 04:13:29 -0400 |
---|---|---|
committer | Doug Ledford <dledford@redhat.com> | 2018-10-16 14:36:21 -0400 |
commit | 90f6e41cc03a4055d56e94ad7c97df4b1add7f61 (patch) | |
tree | 4862901356fa3a741226db9807f0d4dcad8afb7f | |
parent | 7d65cbf0b0ac7d7eebf397ff9af6645b2b3004c2 (diff) |
RDMA/uverbs: Use kernel API to allocate uverbs indexes
Replace custom code to allocate indexes to generic kernel API.
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
-rw-r--r-- | drivers/infiniband/core/uverbs_main.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c index 4258cbd55ed7..6d373f5515b7 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c | |||
@@ -73,7 +73,7 @@ enum { | |||
73 | static dev_t dynamic_uverbs_dev; | 73 | static dev_t dynamic_uverbs_dev; |
74 | static struct class *uverbs_class; | 74 | static struct class *uverbs_class; |
75 | 75 | ||
76 | static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); | 76 | static DEFINE_IDA(uverbs_ida); |
77 | 77 | ||
78 | static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, | 78 | static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file, |
79 | const char __user *buf, int in_len, | 79 | const char __user *buf, int in_len, |
@@ -1268,11 +1268,11 @@ static void ib_uverbs_add_one(struct ib_device *device) | |||
1268 | rcu_assign_pointer(uverbs_dev->ib_dev, device); | 1268 | rcu_assign_pointer(uverbs_dev->ib_dev, device); |
1269 | uverbs_dev->num_comp_vectors = device->num_comp_vectors; | 1269 | uverbs_dev->num_comp_vectors = device->num_comp_vectors; |
1270 | 1270 | ||
1271 | devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES); | 1271 | devnum = ida_alloc_max(&uverbs_ida, IB_UVERBS_MAX_DEVICES - 1, |
1272 | if (devnum >= IB_UVERBS_MAX_DEVICES) | 1272 | GFP_KERNEL); |
1273 | if (devnum < 0) | ||
1273 | goto err; | 1274 | goto err; |
1274 | uverbs_dev->devnum = devnum; | 1275 | uverbs_dev->devnum = devnum; |
1275 | set_bit(devnum, dev_map); | ||
1276 | if (devnum >= IB_UVERBS_NUM_FIXED_MINOR) | 1276 | if (devnum >= IB_UVERBS_NUM_FIXED_MINOR) |
1277 | base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR; | 1277 | base = dynamic_uverbs_dev + devnum - IB_UVERBS_NUM_FIXED_MINOR; |
1278 | else | 1278 | else |
@@ -1296,7 +1296,7 @@ static void ib_uverbs_add_one(struct ib_device *device) | |||
1296 | return; | 1296 | return; |
1297 | 1297 | ||
1298 | err_uapi: | 1298 | err_uapi: |
1299 | clear_bit(devnum, dev_map); | 1299 | ida_free(&uverbs_ida, devnum); |
1300 | err: | 1300 | err: |
1301 | if (atomic_dec_and_test(&uverbs_dev->refcount)) | 1301 | if (atomic_dec_and_test(&uverbs_dev->refcount)) |
1302 | ib_uverbs_comp_dev(uverbs_dev); | 1302 | ib_uverbs_comp_dev(uverbs_dev); |
@@ -1371,7 +1371,7 @@ static void ib_uverbs_remove_one(struct ib_device *device, void *client_data) | |||
1371 | return; | 1371 | return; |
1372 | 1372 | ||
1373 | cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev); | 1373 | cdev_device_del(&uverbs_dev->cdev, &uverbs_dev->dev); |
1374 | clear_bit(uverbs_dev->devnum, dev_map); | 1374 | ida_free(&uverbs_ida, uverbs_dev->devnum); |
1375 | 1375 | ||
1376 | if (device->disassociate_ucontext) { | 1376 | if (device->disassociate_ucontext) { |
1377 | /* We disassociate HW resources and immediately return. | 1377 | /* We disassociate HW resources and immediately return. |