@@ -165,6 +165,35 @@ static int alloc_name(char *name)
165
165
return 0 ;
166
166
}
167
167
168
+ static void ib_device_release (struct device * device )
169
+ {
170
+ struct ib_device * dev = container_of (device , struct ib_device , dev );
171
+
172
+ kfree (dev -> port_immutable );
173
+ kfree (dev );
174
+ }
175
+
176
+ static int ib_device_uevent (struct device * device ,
177
+ struct kobj_uevent_env * env )
178
+ {
179
+ struct ib_device * dev = container_of (device , struct ib_device , dev );
180
+
181
+ if (add_uevent_var (env , "NAME=%s" , dev -> name ))
182
+ return - ENOMEM ;
183
+
184
+ /*
185
+ * It would be nice to pass the node GUID with the event...
186
+ */
187
+
188
+ return 0 ;
189
+ }
190
+
191
+ static struct class ib_class = {
192
+ .name = "infiniband" ,
193
+ .dev_release = ib_device_release ,
194
+ .dev_uevent = ib_device_uevent ,
195
+ };
196
+
168
197
/**
169
198
* ib_alloc_device - allocate an IB device struct
170
199
* @size:size of structure to allocate
@@ -177,9 +206,27 @@ static int alloc_name(char *name)
177
206
*/
178
207
struct ib_device * ib_alloc_device (size_t size )
179
208
{
180
- BUG_ON (size < sizeof (struct ib_device ));
209
+ struct ib_device * device ;
210
+
211
+ if (WARN_ON (size < sizeof (struct ib_device )))
212
+ return NULL ;
213
+
214
+ device = kzalloc (size , GFP_KERNEL );
215
+ if (!device )
216
+ return NULL ;
217
+
218
+ device -> dev .class = & ib_class ;
219
+ device_initialize (& device -> dev );
220
+
221
+ dev_set_drvdata (& device -> dev , device );
222
+
223
+ INIT_LIST_HEAD (& device -> event_handler_list );
224
+ spin_lock_init (& device -> event_handler_lock );
225
+ spin_lock_init (& device -> client_data_lock );
226
+ INIT_LIST_HEAD (& device -> client_data_list );
227
+ INIT_LIST_HEAD (& device -> port_list );
181
228
182
- return kzalloc ( size , GFP_KERNEL ) ;
229
+ return device ;
183
230
}
184
231
EXPORT_SYMBOL (ib_alloc_device );
185
232
@@ -191,13 +238,8 @@ EXPORT_SYMBOL(ib_alloc_device);
191
238
*/
192
239
void ib_dealloc_device (struct ib_device * device )
193
240
{
194
- if (device -> reg_state == IB_DEV_UNINITIALIZED ) {
195
- kfree (device );
196
- return ;
197
- }
198
-
199
- BUG_ON (device -> reg_state != IB_DEV_UNREGISTERED );
200
-
241
+ WARN_ON (device -> reg_state != IB_DEV_UNREGISTERED &&
242
+ device -> reg_state != IB_DEV_UNINITIALIZED );
201
243
kobject_put (& device -> dev .kobj );
202
244
}
203
245
EXPORT_SYMBOL (ib_dealloc_device );
@@ -235,7 +277,7 @@ static int verify_immutable(const struct ib_device *dev, u8 port)
235
277
236
278
static int read_port_immutable (struct ib_device * device )
237
279
{
238
- int ret = - ENOMEM ;
280
+ int ret ;
239
281
u8 start_port = rdma_start_port (device );
240
282
u8 end_port = rdma_end_port (device );
241
283
u8 port ;
@@ -251,26 +293,18 @@ static int read_port_immutable(struct ib_device *device)
251
293
* (end_port + 1 ),
252
294
GFP_KERNEL );
253
295
if (!device -> port_immutable )
254
- goto err ;
296
+ return - ENOMEM ;
255
297
256
298
for (port = start_port ; port <= end_port ; ++ port ) {
257
299
ret = device -> get_port_immutable (device , port ,
258
300
& device -> port_immutable [port ]);
259
301
if (ret )
260
- goto err ;
302
+ return ret ;
261
303
262
- if (verify_immutable (device , port )) {
263
- ret = - EINVAL ;
264
- goto err ;
265
- }
304
+ if (verify_immutable (device , port ))
305
+ return - EINVAL ;
266
306
}
267
-
268
- ret = 0 ;
269
- goto out ;
270
- err :
271
- kfree (device -> port_immutable );
272
- out :
273
- return ret ;
307
+ return 0 ;
274
308
}
275
309
276
310
/**
@@ -301,11 +335,6 @@ int ib_register_device(struct ib_device *device,
301
335
goto out ;
302
336
}
303
337
304
- INIT_LIST_HEAD (& device -> event_handler_list );
305
- INIT_LIST_HEAD (& device -> client_data_list );
306
- spin_lock_init (& device -> event_handler_lock );
307
- spin_lock_init (& device -> client_data_lock );
308
-
309
338
ret = read_port_immutable (device );
310
339
if (ret ) {
311
340
printk (KERN_WARNING "Couldn't create per port immutable data %s\n" ,
@@ -317,7 +346,6 @@ int ib_register_device(struct ib_device *device,
317
346
if (ret ) {
318
347
printk (KERN_WARNING "Couldn't register device %s with driver model\n" ,
319
348
device -> name );
320
- kfree (device -> port_immutable );
321
349
goto out ;
322
350
}
323
351
@@ -834,7 +862,7 @@ static int __init ib_core_init(void)
834
862
if (!ib_wq )
835
863
return - ENOMEM ;
836
864
837
- ret = ib_sysfs_setup ( );
865
+ ret = class_register ( & ib_class );
838
866
if (ret ) {
839
867
printk (KERN_WARNING "Couldn't create InfiniBand device class\n" );
840
868
goto err ;
@@ -858,7 +886,7 @@ static int __init ib_core_init(void)
858
886
ibnl_cleanup ();
859
887
860
888
err_sysfs :
861
- ib_sysfs_cleanup ( );
889
+ class_unregister ( & ib_class );
862
890
863
891
err :
864
892
destroy_workqueue (ib_wq );
@@ -869,7 +897,7 @@ static void __exit ib_core_cleanup(void)
869
897
{
870
898
ib_cache_cleanup ();
871
899
ibnl_cleanup ();
872
- ib_sysfs_cleanup ( );
900
+ class_unregister ( & ib_class );
873
901
/* Make sure that any pending umem accounting work is done. */
874
902
destroy_workqueue (ib_wq );
875
903
}
0 commit comments