Skip to content

Commit

Permalink
IB/uverbs: Use stack variable 'devnum' in ib_uverbs_add_one
Browse files Browse the repository at this point in the history
This change is not useful by itself, but it sets us up for a future
change that allows us to dynamically allocate device numbers in case
we have more than IB_UVERBS_MAX_DEVICES in the system.

Signed-off-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
  • Loading branch information
Alexander Chiang authored and Roland Dreier committed Feb 24, 2010
1 parent 2a72f21 commit 3870798
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/infiniband/core/uverbs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ static CLASS_ATTR(abi_version, S_IRUGO, show_abi_version, NULL);

static void ib_uverbs_add_one(struct ib_device *device)
{
int devnum;
struct ib_uverbs_device *uverbs_dev;

if (!device->alloc_ucontext)
Expand All @@ -743,12 +744,13 @@ static void ib_uverbs_add_one(struct ib_device *device)
init_completion(&uverbs_dev->comp);

spin_lock(&map_lock);
uverbs_dev->devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
if (uverbs_dev->devnum >= IB_UVERBS_MAX_DEVICES) {
devnum = find_first_zero_bit(dev_map, IB_UVERBS_MAX_DEVICES);
if (devnum >= IB_UVERBS_MAX_DEVICES) {
spin_unlock(&map_lock);
goto err;
}
set_bit(uverbs_dev->devnum, dev_map);
uverbs_dev->devnum = devnum;
set_bit(devnum, dev_map);
spin_unlock(&map_lock);

uverbs_dev->ib_dev = device;
Expand All @@ -758,7 +760,7 @@ static void ib_uverbs_add_one(struct ib_device *device)
uverbs_dev->cdev.owner = THIS_MODULE;
uverbs_dev->cdev.ops = device->mmap ? &uverbs_mmap_fops : &uverbs_fops;
kobject_set_name(&uverbs_dev->cdev.kobj, "uverbs%d", uverbs_dev->devnum);
if (cdev_add(&uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
if (cdev_add(&uverbs_dev->cdev, IB_UVERBS_BASE_DEV + devnum, 1))
goto err_cdev;

uverbs_dev->dev = device_create(uverbs_class, device->dma_device,
Expand All @@ -781,7 +783,7 @@ static void ib_uverbs_add_one(struct ib_device *device)

err_cdev:
cdev_del(&uverbs_dev->cdev);
clear_bit(uverbs_dev->devnum, dev_map);
clear_bit(devnum, dev_map);

err:
kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);
Expand Down

0 comments on commit 3870798

Please sign in to comment.