@@ -402,7 +402,7 @@ static ssize_t description_show(struct device *dev,
402
402
struct device_attribute * attr ,
403
403
char * buf )
404
404
{
405
- struct most_interface * iface = to_most_interface (dev );
405
+ struct most_interface * iface = dev_get_drvdata (dev );
406
406
407
407
return snprintf (buf , PAGE_SIZE , "%s\n" , iface -> description );
408
408
}
@@ -411,7 +411,7 @@ static ssize_t interface_show(struct device *dev,
411
411
struct device_attribute * attr ,
412
412
char * buf )
413
413
{
414
- struct most_interface * iface = to_most_interface (dev );
414
+ struct most_interface * iface = dev_get_drvdata (dev );
415
415
416
416
switch (iface -> interface ) {
417
417
case ITYPE_LOOPBACK :
@@ -476,23 +476,23 @@ static int print_links(struct device *dev, void *data)
476
476
int offs = d -> offs ;
477
477
char * buf = d -> buf ;
478
478
struct most_channel * c ;
479
- struct most_interface * iface = to_most_interface (dev );
479
+ struct most_interface * iface = dev_get_drvdata (dev );
480
480
481
481
list_for_each_entry (c , & iface -> p -> channel_list , list ) {
482
482
if (c -> pipe0 .comp ) {
483
483
offs += snprintf (buf + offs ,
484
484
PAGE_SIZE - offs ,
485
485
"%s:%s:%s\n" ,
486
486
c -> pipe0 .comp -> name ,
487
- dev_name (& iface -> dev ),
487
+ dev_name (iface -> dev ),
488
488
dev_name (& c -> dev ));
489
489
}
490
490
if (c -> pipe1 .comp ) {
491
491
offs += snprintf (buf + offs ,
492
492
PAGE_SIZE - offs ,
493
493
"%s:%s:%s\n" ,
494
494
c -> pipe1 .comp -> name ,
495
- dev_name (& iface -> dev ),
495
+ dev_name (iface -> dev ),
496
496
dev_name (& c -> dev ));
497
497
}
498
498
}
@@ -534,7 +534,7 @@ static struct most_channel *get_channel(char *mdev, char *mdev_ch)
534
534
dev = bus_find_device_by_name (& mc .bus , NULL , mdev );
535
535
if (!dev )
536
536
return NULL ;
537
- iface = to_most_interface (dev );
537
+ iface = dev_get_drvdata (dev );
538
538
list_for_each_entry_safe (c , tmp , & iface -> p -> channel_list , list ) {
539
539
if (!strcmp (dev_name (& c -> dev ), mdev_ch ))
540
540
return c ;
@@ -1232,7 +1232,7 @@ static int disconnect_channels(struct device *dev, void *data)
1232
1232
struct most_channel * c , * tmp ;
1233
1233
struct most_component * comp = data ;
1234
1234
1235
- iface = to_most_interface (dev );
1235
+ iface = dev_get_drvdata (dev );
1236
1236
list_for_each_entry_safe (c , tmp , & iface -> p -> channel_list , list ) {
1237
1237
if (c -> pipe0 .comp == comp || c -> pipe1 .comp == comp )
1238
1238
comp -> disconnect_channel (c -> iface , c -> channel_id );
@@ -1261,14 +1261,11 @@ int most_deregister_component(struct most_component *comp)
1261
1261
}
1262
1262
EXPORT_SYMBOL_GPL (most_deregister_component );
1263
1263
1264
- static void release_interface (struct device * dev )
1265
- {
1266
- dev_info (& mc .dev , "releasing interface dev %s...\n" , dev_name (dev ));
1267
- }
1268
-
1269
1264
static void release_channel (struct device * dev )
1270
1265
{
1271
- dev_info (& mc .dev , "releasing channel dev %s...\n" , dev_name (dev ));
1266
+ struct most_channel * c = to_channel (dev );
1267
+
1268
+ kfree (c );
1272
1269
}
1273
1270
1274
1271
/**
@@ -1305,14 +1302,14 @@ int most_register_interface(struct most_interface *iface)
1305
1302
INIT_LIST_HEAD (& iface -> p -> channel_list );
1306
1303
iface -> p -> dev_id = id ;
1307
1304
strscpy (iface -> p -> name , iface -> description , sizeof (iface -> p -> name ));
1308
- iface -> dev .init_name = iface -> p -> name ;
1309
- iface -> dev .bus = & mc .bus ;
1310
- iface -> dev .parent = & mc .dev ;
1311
- iface -> dev .groups = interface_attr_groups ;
1312
- iface -> dev .release = release_interface ;
1313
- if (device_register (& iface -> dev )) {
1305
+ iface -> dev -> bus = & mc .bus ;
1306
+ iface -> dev -> parent = & mc .dev ;
1307
+ iface -> dev -> groups = interface_attr_groups ;
1308
+ dev_set_drvdata (iface -> dev , iface );
1309
+ if (device_register (iface -> dev )) {
1314
1310
dev_err (& mc .dev , "registering iface->dev failed\n" );
1315
1311
kfree (iface -> p );
1312
+ put_device (iface -> dev );
1316
1313
ida_simple_remove (& mdev_id , id );
1317
1314
return - ENOMEM ;
1318
1315
}
@@ -1328,7 +1325,7 @@ int most_register_interface(struct most_interface *iface)
1328
1325
else
1329
1326
snprintf (c -> name , STRING_SIZE , "%s" , name_suffix );
1330
1327
c -> dev .init_name = c -> name ;
1331
- c -> dev .parent = & iface -> dev ;
1328
+ c -> dev .parent = iface -> dev ;
1332
1329
c -> dev .groups = channel_attr_groups ;
1333
1330
c -> dev .release = release_channel ;
1334
1331
iface -> p -> channel [i ] = c ;
@@ -1362,16 +1359,15 @@ int most_register_interface(struct most_interface *iface)
1362
1359
return 0 ;
1363
1360
1364
1361
err_free_most_channel :
1365
- kfree ( c );
1362
+ put_device ( & c -> dev );
1366
1363
1367
1364
err_free_resources :
1368
1365
while (i > 0 ) {
1369
1366
c = iface -> p -> channel [-- i ];
1370
1367
device_unregister (& c -> dev );
1371
- kfree (c );
1372
1368
}
1373
1369
kfree (iface -> p );
1374
- device_unregister (& iface -> dev );
1370
+ device_unregister (iface -> dev );
1375
1371
ida_simple_remove (& mdev_id , id );
1376
1372
return - ENOMEM ;
1377
1373
}
@@ -1401,12 +1397,11 @@ void most_deregister_interface(struct most_interface *iface)
1401
1397
c -> pipe1 .comp = NULL ;
1402
1398
list_del (& c -> list );
1403
1399
device_unregister (& c -> dev );
1404
- kfree (c );
1405
1400
}
1406
1401
1407
1402
ida_simple_remove (& mdev_id , iface -> p -> dev_id );
1408
1403
kfree (iface -> p );
1409
- device_unregister (& iface -> dev );
1404
+ device_unregister (iface -> dev );
1410
1405
}
1411
1406
EXPORT_SYMBOL_GPL (most_deregister_interface );
1412
1407
0 commit comments