@@ -402,7 +402,7 @@ static ssize_t description_show(struct device *dev,
402402 struct device_attribute * attr ,
403403 char * buf )
404404{
405- struct most_interface * iface = to_most_interface (dev );
405+ struct most_interface * iface = dev_get_drvdata (dev );
406406
407407 return snprintf (buf , PAGE_SIZE , "%s\n" , iface -> description );
408408}
@@ -411,7 +411,7 @@ static ssize_t interface_show(struct device *dev,
411411 struct device_attribute * attr ,
412412 char * buf )
413413{
414- struct most_interface * iface = to_most_interface (dev );
414+ struct most_interface * iface = dev_get_drvdata (dev );
415415
416416 switch (iface -> interface ) {
417417 case ITYPE_LOOPBACK :
@@ -476,23 +476,23 @@ static int print_links(struct device *dev, void *data)
476476 int offs = d -> offs ;
477477 char * buf = d -> buf ;
478478 struct most_channel * c ;
479- struct most_interface * iface = to_most_interface (dev );
479+ struct most_interface * iface = dev_get_drvdata (dev );
480480
481481 list_for_each_entry (c , & iface -> p -> channel_list , list ) {
482482 if (c -> pipe0 .comp ) {
483483 offs += snprintf (buf + offs ,
484484 PAGE_SIZE - offs ,
485485 "%s:%s:%s\n" ,
486486 c -> pipe0 .comp -> name ,
487- dev_name (& iface -> dev ),
487+ dev_name (iface -> dev ),
488488 dev_name (& c -> dev ));
489489 }
490490 if (c -> pipe1 .comp ) {
491491 offs += snprintf (buf + offs ,
492492 PAGE_SIZE - offs ,
493493 "%s:%s:%s\n" ,
494494 c -> pipe1 .comp -> name ,
495- dev_name (& iface -> dev ),
495+ dev_name (iface -> dev ),
496496 dev_name (& c -> dev ));
497497 }
498498 }
@@ -534,7 +534,7 @@ static struct most_channel *get_channel(char *mdev, char *mdev_ch)
534534 dev = bus_find_device_by_name (& mc .bus , NULL , mdev );
535535 if (!dev )
536536 return NULL ;
537- iface = to_most_interface (dev );
537+ iface = dev_get_drvdata (dev );
538538 list_for_each_entry_safe (c , tmp , & iface -> p -> channel_list , list ) {
539539 if (!strcmp (dev_name (& c -> dev ), mdev_ch ))
540540 return c ;
@@ -1232,7 +1232,7 @@ static int disconnect_channels(struct device *dev, void *data)
12321232 struct most_channel * c , * tmp ;
12331233 struct most_component * comp = data ;
12341234
1235- iface = to_most_interface (dev );
1235+ iface = dev_get_drvdata (dev );
12361236 list_for_each_entry_safe (c , tmp , & iface -> p -> channel_list , list ) {
12371237 if (c -> pipe0 .comp == comp || c -> pipe1 .comp == comp )
12381238 comp -> disconnect_channel (c -> iface , c -> channel_id );
@@ -1261,14 +1261,11 @@ int most_deregister_component(struct most_component *comp)
12611261}
12621262EXPORT_SYMBOL_GPL (most_deregister_component );
12631263
1264- static void release_interface (struct device * dev )
1265- {
1266- dev_info (& mc .dev , "releasing interface dev %s...\n" , dev_name (dev ));
1267- }
1268-
12691264static void release_channel (struct device * dev )
12701265{
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 );
12721269}
12731270
12741271/**
@@ -1305,14 +1302,14 @@ int most_register_interface(struct most_interface *iface)
13051302 INIT_LIST_HEAD (& iface -> p -> channel_list );
13061303 iface -> p -> dev_id = id ;
13071304 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 )) {
13141310 dev_err (& mc .dev , "registering iface->dev failed\n" );
13151311 kfree (iface -> p );
1312+ put_device (iface -> dev );
13161313 ida_simple_remove (& mdev_id , id );
13171314 return - ENOMEM ;
13181315 }
@@ -1328,7 +1325,7 @@ int most_register_interface(struct most_interface *iface)
13281325 else
13291326 snprintf (c -> name , STRING_SIZE , "%s" , name_suffix );
13301327 c -> dev .init_name = c -> name ;
1331- c -> dev .parent = & iface -> dev ;
1328+ c -> dev .parent = iface -> dev ;
13321329 c -> dev .groups = channel_attr_groups ;
13331330 c -> dev .release = release_channel ;
13341331 iface -> p -> channel [i ] = c ;
@@ -1362,16 +1359,15 @@ int most_register_interface(struct most_interface *iface)
13621359 return 0 ;
13631360
13641361err_free_most_channel :
1365- kfree ( c );
1362+ put_device ( & c -> dev );
13661363
13671364err_free_resources :
13681365 while (i > 0 ) {
13691366 c = iface -> p -> channel [-- i ];
13701367 device_unregister (& c -> dev );
1371- kfree (c );
13721368 }
13731369 kfree (iface -> p );
1374- device_unregister (& iface -> dev );
1370+ device_unregister (iface -> dev );
13751371 ida_simple_remove (& mdev_id , id );
13761372 return - ENOMEM ;
13771373}
@@ -1401,12 +1397,11 @@ void most_deregister_interface(struct most_interface *iface)
14011397 c -> pipe1 .comp = NULL ;
14021398 list_del (& c -> list );
14031399 device_unregister (& c -> dev );
1404- kfree (c );
14051400 }
14061401
14071402 ida_simple_remove (& mdev_id , iface -> p -> dev_id );
14081403 kfree (iface -> p );
1409- device_unregister (& iface -> dev );
1404+ device_unregister (iface -> dev );
14101405}
14111406EXPORT_SYMBOL_GPL (most_deregister_interface );
14121407
0 commit comments