Skip to content

Commit 2a72f21

Browse files
Alexander ChiangRoland Dreier
authored andcommitted
IB/uverbs: Remove dev_table
dev_table's raison d'etre was to associate an inode back to a struct ib_uverbs_device. However, now that we've converted ib_uverbs_device to contain an embedded cdev (instead of a *cdev), we can use the container_of() macro and cast back to the containing device. There's no longer any need for dev_table, so get rid of it. Signed-off-by: Alex Chiang <achiang@hp.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent 055422d commit 2a72f21

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

drivers/infiniband/core/uverbs_main.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ DEFINE_IDR(ib_uverbs_qp_idr);
7474
DEFINE_IDR(ib_uverbs_srq_idr);
7575

7676
static DEFINE_SPINLOCK(map_lock);
77-
static struct ib_uverbs_device *dev_table[IB_UVERBS_MAX_DEVICES];
7877
static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
7978

8079
static ssize_t (*uverbs_cmd_table[])(struct ib_uverbs_file *file,
@@ -616,28 +615,23 @@ static int ib_uverbs_mmap(struct file *filp, struct vm_area_struct *vma)
616615
/*
617616
* ib_uverbs_open() does not need the BKL:
618617
*
619-
* - dev_table[] accesses are protected by map_lock, the
620-
* ib_uverbs_device structures are properly reference counted, and
618+
* - the ib_uverbs_device structures are properly reference counted and
621619
* everything else is purely local to the file being created, so
622620
* races against other open calls are not a problem;
623621
* - there is no ioctl method to race against;
624-
* - the device is added to dev_table[] as the last part of module
625-
* initialization, the open method will either immediately run
626-
* -ENXIO, or all required initialization will be done.
622+
* - the open method will either immediately run -ENXIO, or all
623+
* required initialization will be done.
627624
*/
628625
static int ib_uverbs_open(struct inode *inode, struct file *filp)
629626
{
630627
struct ib_uverbs_device *dev;
631628
struct ib_uverbs_file *file;
632629
int ret;
633630

634-
spin_lock(&map_lock);
635-
dev = dev_table[iminor(inode) - IB_UVERBS_BASE_MINOR];
631+
dev = container_of(inode->i_cdev, struct ib_uverbs_device, cdev);
636632
if (dev)
637633
kref_get(&dev->ref);
638-
spin_unlock(&map_lock);
639-
640-
if (!dev)
634+
else
641635
return -ENXIO;
642636

643637
if (!try_module_get(dev->ib_dev->owner)) {
@@ -778,10 +772,6 @@ static void ib_uverbs_add_one(struct ib_device *device)
778772
if (device_create_file(uverbs_dev->dev, &dev_attr_abi_version))
779773
goto err_class;
780774

781-
spin_lock(&map_lock);
782-
dev_table[uverbs_dev->devnum] = uverbs_dev;
783-
spin_unlock(&map_lock);
784-
785775
ib_set_client_data(device, &uverbs_client, uverbs_dev);
786776

787777
return;
@@ -811,10 +801,6 @@ static void ib_uverbs_remove_one(struct ib_device *device)
811801
device_destroy(uverbs_class, uverbs_dev->cdev.dev);
812802
cdev_del(&uverbs_dev->cdev);
813803

814-
spin_lock(&map_lock);
815-
dev_table[uverbs_dev->devnum] = NULL;
816-
spin_unlock(&map_lock);
817-
818804
clear_bit(uverbs_dev->devnum, dev_map);
819805

820806
kref_put(&uverbs_dev->ref, ib_uverbs_release_dev);

0 commit comments

Comments
 (0)