diff options
-rw-r--r-- | drivers/infiniband/core/user_mad.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 9bdf576cd4ab..1acb99100556 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c | |||
@@ -98,7 +98,7 @@ struct ib_umad_port { | |||
98 | 98 | ||
99 | struct ib_umad_device { | 99 | struct ib_umad_device { |
100 | int start_port, end_port; | 100 | int start_port, end_port; |
101 | struct kref ref; | 101 | struct kobject kobj; |
102 | struct ib_umad_port port[0]; | 102 | struct ib_umad_port port[0]; |
103 | }; | 103 | }; |
104 | 104 | ||
@@ -134,14 +134,18 @@ static DECLARE_BITMAP(dev_map, IB_UMAD_MAX_PORTS); | |||
134 | static void ib_umad_add_one(struct ib_device *device); | 134 | static void ib_umad_add_one(struct ib_device *device); |
135 | static void ib_umad_remove_one(struct ib_device *device); | 135 | static void ib_umad_remove_one(struct ib_device *device); |
136 | 136 | ||
137 | static void ib_umad_release_dev(struct kref *ref) | 137 | static void ib_umad_release_dev(struct kobject *kobj) |
138 | { | 138 | { |
139 | struct ib_umad_device *dev = | 139 | struct ib_umad_device *dev = |
140 | container_of(ref, struct ib_umad_device, ref); | 140 | container_of(kobj, struct ib_umad_device, kobj); |
141 | 141 | ||
142 | kfree(dev); | 142 | kfree(dev); |
143 | } | 143 | } |
144 | 144 | ||
145 | static struct kobj_type ib_umad_dev_ktype = { | ||
146 | .release = ib_umad_release_dev, | ||
147 | }; | ||
148 | |||
145 | static int hdr_size(struct ib_umad_file *file) | 149 | static int hdr_size(struct ib_umad_file *file) |
146 | { | 150 | { |
147 | return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) : | 151 | return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) : |
@@ -812,7 +816,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp) | |||
812 | goto out; | 816 | goto out; |
813 | } | 817 | } |
814 | 818 | ||
815 | kref_get(&port->umad_dev->ref); | 819 | kobject_get(&port->umad_dev->kobj); |
816 | 820 | ||
817 | out: | 821 | out: |
818 | mutex_unlock(&port->file_mutex); | 822 | mutex_unlock(&port->file_mutex); |
@@ -851,7 +855,7 @@ static int ib_umad_close(struct inode *inode, struct file *filp) | |||
851 | mutex_unlock(&file->port->file_mutex); | 855 | mutex_unlock(&file->port->file_mutex); |
852 | 856 | ||
853 | kfree(file); | 857 | kfree(file); |
854 | kref_put(&dev->ref, ib_umad_release_dev); | 858 | kobject_put(&dev->kobj); |
855 | 859 | ||
856 | return 0; | 860 | return 0; |
857 | } | 861 | } |
@@ -902,7 +906,7 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp) | |||
902 | if (ret) | 906 | if (ret) |
903 | goto err_clr_sm_cap; | 907 | goto err_clr_sm_cap; |
904 | 908 | ||
905 | kref_get(&port->umad_dev->ref); | 909 | kobject_get(&port->umad_dev->kobj); |
906 | 910 | ||
907 | return 0; | 911 | return 0; |
908 | 912 | ||
@@ -932,7 +936,7 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp) | |||
932 | 936 | ||
933 | up(&port->sm_sem); | 937 | up(&port->sm_sem); |
934 | 938 | ||
935 | kref_put(&port->umad_dev->ref, ib_umad_release_dev); | 939 | kobject_put(&port->umad_dev->kobj); |
936 | 940 | ||
937 | return ret; | 941 | return ret; |
938 | } | 942 | } |
@@ -1000,6 +1004,7 @@ static int find_overflow_devnum(void) | |||
1000 | } | 1004 | } |
1001 | 1005 | ||
1002 | static int ib_umad_init_port(struct ib_device *device, int port_num, | 1006 | static int ib_umad_init_port(struct ib_device *device, int port_num, |
1007 | struct ib_umad_device *umad_dev, | ||
1003 | struct ib_umad_port *port) | 1008 | struct ib_umad_port *port) |
1004 | { | 1009 | { |
1005 | int devnum; | 1010 | int devnum; |
@@ -1032,6 +1037,7 @@ static int ib_umad_init_port(struct ib_device *device, int port_num, | |||
1032 | 1037 | ||
1033 | cdev_init(&port->cdev, &umad_fops); | 1038 | cdev_init(&port->cdev, &umad_fops); |
1034 | port->cdev.owner = THIS_MODULE; | 1039 | port->cdev.owner = THIS_MODULE; |
1040 | port->cdev.kobj.parent = &umad_dev->kobj; | ||
1035 | kobject_set_name(&port->cdev.kobj, "umad%d", port->dev_num); | 1041 | kobject_set_name(&port->cdev.kobj, "umad%d", port->dev_num); |
1036 | if (cdev_add(&port->cdev, base, 1)) | 1042 | if (cdev_add(&port->cdev, base, 1)) |
1037 | goto err_cdev; | 1043 | goto err_cdev; |
@@ -1050,6 +1056,7 @@ static int ib_umad_init_port(struct ib_device *device, int port_num, | |||
1050 | base += IB_UMAD_MAX_PORTS; | 1056 | base += IB_UMAD_MAX_PORTS; |
1051 | cdev_init(&port->sm_cdev, &umad_sm_fops); | 1057 | cdev_init(&port->sm_cdev, &umad_sm_fops); |
1052 | port->sm_cdev.owner = THIS_MODULE; | 1058 | port->sm_cdev.owner = THIS_MODULE; |
1059 | port->sm_cdev.kobj.parent = &umad_dev->kobj; | ||
1053 | kobject_set_name(&port->sm_cdev.kobj, "issm%d", port->dev_num); | 1060 | kobject_set_name(&port->sm_cdev.kobj, "issm%d", port->dev_num); |
1054 | if (cdev_add(&port->sm_cdev, base, 1)) | 1061 | if (cdev_add(&port->sm_cdev, base, 1)) |
1055 | goto err_sm_cdev; | 1062 | goto err_sm_cdev; |
@@ -1143,7 +1150,7 @@ static void ib_umad_add_one(struct ib_device *device) | |||
1143 | if (!umad_dev) | 1150 | if (!umad_dev) |
1144 | return; | 1151 | return; |
1145 | 1152 | ||
1146 | kref_init(&umad_dev->ref); | 1153 | kobject_init(&umad_dev->kobj, &ib_umad_dev_ktype); |
1147 | 1154 | ||
1148 | umad_dev->start_port = s; | 1155 | umad_dev->start_port = s; |
1149 | umad_dev->end_port = e; | 1156 | umad_dev->end_port = e; |
@@ -1151,7 +1158,8 @@ static void ib_umad_add_one(struct ib_device *device) | |||
1151 | for (i = s; i <= e; ++i) { | 1158 | for (i = s; i <= e; ++i) { |
1152 | umad_dev->port[i - s].umad_dev = umad_dev; | 1159 | umad_dev->port[i - s].umad_dev = umad_dev; |
1153 | 1160 | ||
1154 | if (ib_umad_init_port(device, i, &umad_dev->port[i - s])) | 1161 | if (ib_umad_init_port(device, i, umad_dev, |
1162 | &umad_dev->port[i - s])) | ||
1155 | goto err; | 1163 | goto err; |
1156 | } | 1164 | } |
1157 | 1165 | ||
@@ -1163,7 +1171,7 @@ err: | |||
1163 | while (--i >= s) | 1171 | while (--i >= s) |
1164 | ib_umad_kill_port(&umad_dev->port[i - s]); | 1172 | ib_umad_kill_port(&umad_dev->port[i - s]); |
1165 | 1173 | ||
1166 | kref_put(&umad_dev->ref, ib_umad_release_dev); | 1174 | kobject_put(&umad_dev->kobj); |
1167 | } | 1175 | } |
1168 | 1176 | ||
1169 | static void ib_umad_remove_one(struct ib_device *device) | 1177 | static void ib_umad_remove_one(struct ib_device *device) |
@@ -1177,7 +1185,7 @@ static void ib_umad_remove_one(struct ib_device *device) | |||
1177 | for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) | 1185 | for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) |
1178 | ib_umad_kill_port(&umad_dev->port[i]); | 1186 | ib_umad_kill_port(&umad_dev->port[i]); |
1179 | 1187 | ||
1180 | kref_put(&umad_dev->ref, ib_umad_release_dev); | 1188 | kobject_put(&umad_dev->kobj); |
1181 | } | 1189 | } |
1182 | 1190 | ||
1183 | static char *umad_devnode(struct device *dev, umode_t *mode) | 1191 | static char *umad_devnode(struct device *dev, umode_t *mode) |