Commit 3b88afd3 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/device: Use an ida instead of a free page in alloc_name

ida is the proper data structure to hold list of clustered small integers
and then allocate an unused integer. Get rid of the convoluted and limited
open-coded bitmap.
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 652432f3
...@@ -213,30 +213,36 @@ int ib_device_rename(struct ib_device *ibdev, const char *name) ...@@ -213,30 +213,36 @@ int ib_device_rename(struct ib_device *ibdev, const char *name)
static int alloc_name(struct ib_device *ibdev, const char *name) static int alloc_name(struct ib_device *ibdev, const char *name)
{ {
unsigned long *inuse;
struct ib_device *device; struct ib_device *device;
struct ida inuse;
int rc;
int i; int i;
inuse = (unsigned long *) get_zeroed_page(GFP_KERNEL); ida_init(&inuse);
if (!inuse)
return -ENOMEM;
list_for_each_entry(device, &device_list, core_list) { list_for_each_entry(device, &device_list, core_list) {
char buf[IB_DEVICE_NAME_MAX]; char buf[IB_DEVICE_NAME_MAX];
if (sscanf(dev_name(&device->dev), name, &i) != 1) if (sscanf(dev_name(&device->dev), name, &i) != 1)
continue; continue;
if (i < 0 || i >= PAGE_SIZE * 8) if (i < 0 || i >= INT_MAX)
continue; continue;
snprintf(buf, sizeof buf, name, i); snprintf(buf, sizeof buf, name, i);
if (!strcmp(buf, dev_name(&device->dev))) if (strcmp(buf, dev_name(&device->dev)) != 0)
set_bit(i, inuse); continue;
rc = ida_alloc_range(&inuse, i, i, GFP_KERNEL);
if (rc < 0)
goto out;
} }
i = find_first_zero_bit(inuse, PAGE_SIZE * 8); rc = ida_alloc(&inuse, GFP_KERNEL);
free_page((unsigned long) inuse); if (rc < 0)
goto out;
return dev_set_name(&ibdev->dev, name, i); rc = dev_set_name(&ibdev->dev, name, rc);
out:
ida_destroy(&inuse);
return rc;
} }
static void ib_device_release(struct device *device) static void ib_device_release(struct device *device)
......
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