@@ -49,7 +49,7 @@ static int emsgs_head_idx, emsgs_tail_idx;
49
49
static struct completion emsgs_comp ;
50
50
static spinlock_t emsgs_lock ;
51
51
static int nblocked_emsgs_readers ;
52
- static struct class * aoe_class ;
52
+
53
53
static struct aoe_chardev chardevs [] = {
54
54
{ MINOR_ERR , "err" },
55
55
{ MINOR_DISCOVER , "discover" },
@@ -58,6 +58,16 @@ static struct aoe_chardev chardevs[] = {
58
58
{ MINOR_FLUSH , "flush" },
59
59
};
60
60
61
+ static char * aoe_devnode (const struct device * dev , umode_t * mode )
62
+ {
63
+ return kasprintf (GFP_KERNEL , "etherd/%s" , dev_name (dev ));
64
+ }
65
+
66
+ static const struct class aoe_class = {
67
+ .name = "aoe" ,
68
+ .devnode = aoe_devnode ,
69
+ };
70
+
61
71
static int
62
72
discover (void )
63
73
{
@@ -273,11 +283,6 @@ static const struct file_operations aoe_fops = {
273
283
.llseek = noop_llseek ,
274
284
};
275
285
276
- static char * aoe_devnode (const struct device * dev , umode_t * mode )
277
- {
278
- return kasprintf (GFP_KERNEL , "etherd/%s" , dev_name (dev ));
279
- }
280
-
281
286
int __init
282
287
aoechr_init (void )
283
288
{
@@ -290,15 +295,14 @@ aoechr_init(void)
290
295
}
291
296
init_completion (& emsgs_comp );
292
297
spin_lock_init (& emsgs_lock );
293
- aoe_class = class_create ( "aoe" );
294
- if (IS_ERR ( aoe_class ) ) {
298
+ n = class_register ( & aoe_class );
299
+ if (n ) {
295
300
unregister_chrdev (AOE_MAJOR , "aoechr" );
296
- return PTR_ERR ( aoe_class ) ;
301
+ return n ;
297
302
}
298
- aoe_class -> devnode = aoe_devnode ;
299
303
300
304
for (i = 0 ; i < ARRAY_SIZE (chardevs ); ++ i )
301
- device_create (aoe_class , NULL ,
305
+ device_create (& aoe_class , NULL ,
302
306
MKDEV (AOE_MAJOR , chardevs [i ].minor ), NULL ,
303
307
chardevs [i ].name );
304
308
@@ -311,8 +315,8 @@ aoechr_exit(void)
311
315
int i ;
312
316
313
317
for (i = 0 ; i < ARRAY_SIZE (chardevs ); ++ i )
314
- device_destroy (aoe_class , MKDEV (AOE_MAJOR , chardevs [i ].minor ));
315
- class_destroy ( aoe_class );
318
+ device_destroy (& aoe_class , MKDEV (AOE_MAJOR , chardevs [i ].minor ));
319
+ class_unregister ( & aoe_class );
316
320
unregister_chrdev (AOE_MAJOR , "aoechr" );
317
321
}
318
322
0 commit comments