diff options
| author | Alexander Chiang <achiang@hp.com> | 2010-02-02 14:08:30 -0500 |
|---|---|---|
| committer | Roland Dreier <rolandd@cisco.com> | 2010-02-24 13:23:44 -0500 |
| commit | 6aa2a86ec430fb1ae739bd065d7ea6596997a2cf (patch) | |
| tree | e26a9fb664c4a9bdf2aafe6efd8ca68bfbdc49b1 /drivers | |
| parent | 2b937afcab34e4f739e2f7cd6062870fbe6b2ccf (diff) | |
IB/umad: Remove port_table[]
We no longer need this data structure, as it was used to associate an
inode back to a struct ib_umad_port during ->open(). But now that
we're embedding a struct cdev in struct ib_umad_port, we can use the
container_of() macro to go from the inode back to the device instead.
Signed-off-by: Alex Chiang <achiang@hp.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/infiniband/core/user_mad.c | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 40440ef1b31c..46c88795cc75 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c | |||
| @@ -65,12 +65,9 @@ enum { | |||
| 65 | }; | 65 | }; |
| 66 | 66 | ||
| 67 | /* | 67 | /* |
| 68 | * Our lifetime rules for these structs are the following: each time a | 68 | * Our lifetime rules for these structs are the following: |
| 69 | * device special file is opened, we look up the corresponding struct | 69 | * device special file is opened, we take a reference on the |
| 70 | * ib_umad_port by minor in the umad_port[] table while holding the | 70 | * ib_umad_port's struct ib_umad_device. We drop these |
| 71 | * port_lock. If this lookup succeeds, we take a reference on the | ||
| 72 | * ib_umad_port's struct ib_umad_device while still holding the | ||
| 73 | * port_lock; if the lookup fails, we fail the open(). We drop these | ||
| 74 | * references in the corresponding close(). | 71 | * references in the corresponding close(). |
| 75 | * | 72 | * |
| 76 | * In addition to references coming from open character devices, there | 73 | * In addition to references coming from open character devices, there |
| @@ -78,12 +75,7 @@ enum { | |||
| 78 | * module's reference taken when allocating the ib_umad_device in | 75 | * module's reference taken when allocating the ib_umad_device in |
| 79 | * ib_umad_add_one(). | 76 | * ib_umad_add_one(). |
| 80 | * | 77 | * |
| 81 | * When destroying an ib_umad_device, we clear all of its | 78 | * When destroying an ib_umad_device, we drop the module's reference. |
| 82 | * ib_umad_ports from umad_port[] while holding port_lock before | ||
| 83 | * dropping the module's reference to the ib_umad_device. This is | ||
| 84 | * always safe because any open() calls will either succeed and obtain | ||
| 85 | * a reference before we clear the umad_port[] entries, or fail after | ||
| 86 | * we clear the umad_port[] entries. | ||
| 87 | */ | 79 | */ |
| 88 | 80 | ||
| 89 | struct ib_umad_port { | 81 | struct ib_umad_port { |
| @@ -136,7 +128,6 @@ static struct class *umad_class; | |||
| 136 | static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); | 128 | static const dev_t base_dev = MKDEV(IB_UMAD_MAJOR, IB_UMAD_MINOR_BASE); |
| 137 | 129 | ||
| 138 | static DEFINE_SPINLOCK(port_lock); | 130 | static DEFINE_SPINLOCK(port_lock); |
| 139 | static struct ib_umad_port *umad_port[IB_UMAD_MAX_PORTS]; | ||
| 140 | static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS); | 131 | static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS); |
| 141 | 132 | ||
| 142 | static void ib_umad_add_one(struct ib_device *device); | 133 | static void ib_umad_add_one(struct ib_device *device); |
| @@ -779,15 +770,11 @@ static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, | |||
| 779 | /* | 770 | /* |
| 780 | * ib_umad_open() does not need the BKL: | 771 | * ib_umad_open() does not need the BKL: |
| 781 | * | 772 | * |
| 782 | * - umad_port[] accesses are protected by port_lock, the | 773 | * - the ib_umad_port structures are properly reference counted, and |
| 783 | * ib_umad_port structures are properly reference counted, and | ||
| 784 | * everything else is purely local to the file being created, so | 774 | * everything else is purely local to the file being created, so |
| 785 | * races against other open calls are not a problem; | 775 | * races against other open calls are not a problem; |
| 786 | * - the ioctl method does not affect any global state outside of the | 776 | * - the ioctl method does not affect any global state outside of the |
| 787 | * file structure being operated on; | 777 | * file structure being operated on; |
| 788 | * - the port is added to umad_port[] as the last part of module | ||
| 789 | * initialization so the open method will either immediately run | ||
| 790 | * -ENXIO, or all required initialization will be done. | ||
| 791 | */ | 778 | */ |
| 792 | static int ib_umad_open(struct inode *inode, struct file *filp) | 779 | static int ib_umad_open(struct inode *inode, struct file *filp) |
| 793 | { | 780 | { |
| @@ -795,13 +782,10 @@ static int ib_umad_open(struct inode *inode, struct file *filp) | |||
| 795 | struct ib_umad_file *file; | 782 | struct ib_umad_file *file; |
| 796 | int ret = 0; | 783 | int ret = 0; |
| 797 | 784 | ||
| 798 | spin_lock(&port_lock); | 785 | port = container_of(inode->i_cdev, struct ib_umad_port, cdev); |
| 799 | port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE]; | ||
| 800 | if (port) | 786 | if (port) |
| 801 | kref_get(&port->umad_dev->ref); | 787 | kref_get(&port->umad_dev->ref); |
| 802 | spin_unlock(&port_lock); | 788 | else |
| 803 | |||
| 804 | if (!port) | ||
| 805 | return -ENXIO; | 789 | return -ENXIO; |
| 806 | 790 | ||
| 807 | mutex_lock(&port->file_mutex); | 791 | mutex_lock(&port->file_mutex); |
| @@ -892,13 +876,10 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp) | |||
| 892 | }; | 876 | }; |
| 893 | int ret; | 877 | int ret; |
| 894 | 878 | ||
| 895 | spin_lock(&port_lock); | 879 | port = container_of(inode->i_cdev, struct ib_umad_port, sm_cdev); |
| 896 | port = umad_port[iminor(inode) - IB_UMAD_MINOR_BASE - IB_UMAD_MAX_PORTS]; | ||
| 897 | if (port) | 880 | if (port) |
| 898 | kref_get(&port->umad_dev->ref); | 881 | kref_get(&port->umad_dev->ref); |
| 899 | spin_unlock(&port_lock); | 882 | else |
| 900 | |||
| 901 | if (!port) | ||
| 902 | return -ENXIO; | 883 | return -ENXIO; |
| 903 | 884 | ||
| 904 | if (filp->f_flags & O_NONBLOCK) { | 885 | if (filp->f_flags & O_NONBLOCK) { |
| @@ -1042,10 +1023,6 @@ static int ib_umad_init_port(struct ib_device *device, int port_num, | |||
| 1042 | if (device_create_file(port->sm_dev, &dev_attr_port)) | 1023 | if (device_create_file(port->sm_dev, &dev_attr_port)) |
| 1043 | goto err_sm_dev; | 1024 | goto err_sm_dev; |
| 1044 | 1025 | ||
| 1045 | spin_lock(&port_lock); | ||
| 1046 | umad_port[port->dev_num] = port; | ||
| 1047 | spin_unlock(&port_lock); | ||
| 1048 | |||
| 1049 | return 0; | 1026 | return 0; |
| 1050 | 1027 | ||
| 1051 | err_sm_dev: | 1028 | err_sm_dev: |
| @@ -1079,10 +1056,6 @@ static void ib_umad_kill_port(struct ib_umad_port *port) | |||
| 1079 | cdev_del(&port->cdev); | 1056 | cdev_del(&port->cdev); |
| 1080 | cdev_del(&port->sm_cdev); | 1057 | cdev_del(&port->sm_cdev); |
| 1081 | 1058 | ||
| 1082 | spin_lock(&port_lock); | ||
| 1083 | umad_port[port->dev_num] = NULL; | ||
| 1084 | spin_unlock(&port_lock); | ||
| 1085 | |||
| 1086 | mutex_lock(&port->file_mutex); | 1059 | mutex_lock(&port->file_mutex); |
| 1087 | 1060 | ||
| 1088 | port->ib_dev = NULL; | 1061 | port->ib_dev = NULL; |
