@@ -16,16 +16,6 @@ static char *idxd_wq_type_names[] = {
1616 [IDXD_WQT_USER ] = "user" ,
1717};
1818
19- static void idxd_conf_sub_device_release (struct device * dev )
20- {
21- dev_dbg (dev , "%s for %s\n" , __func__ , dev_name (dev ));
22- }
23-
24- static struct device_type idxd_group_device_type = {
25- .name = "group" ,
26- .release = idxd_conf_sub_device_release ,
27- };
28-
2919static int idxd_config_bus_match (struct device * dev ,
3020 struct device_driver * drv )
3121{
@@ -435,7 +425,7 @@ static ssize_t engine_group_id_store(struct device *dev,
435425
436426 if (prevg )
437427 prevg -> num_engines -- ;
438- engine -> group = & idxd -> groups [id ];
428+ engine -> group = idxd -> groups [id ];
439429 engine -> group -> num_engines ++ ;
440430
441431 return count ;
@@ -479,7 +469,7 @@ static void idxd_set_free_tokens(struct idxd_device *idxd)
479469 int i , tokens ;
480470
481471 for (i = 0 , tokens = 0 ; i < idxd -> max_groups ; i ++ ) {
482- struct idxd_group * g = & idxd -> groups [i ];
472+ struct idxd_group * g = idxd -> groups [i ];
483473
484474 tokens += g -> tokens_reserved ;
485475 }
@@ -784,6 +774,19 @@ static const struct attribute_group *idxd_group_attribute_groups[] = {
784774 NULL ,
785775};
786776
777+ static void idxd_conf_group_release (struct device * dev )
778+ {
779+ struct idxd_group * group = container_of (dev , struct idxd_group , conf_dev );
780+
781+ kfree (group );
782+ }
783+
784+ struct device_type idxd_group_device_type = {
785+ .name = "group" ,
786+ .release = idxd_conf_group_release ,
787+ .groups = idxd_group_attribute_groups ,
788+ };
789+
787790/* IDXD work queue attribs */
788791static ssize_t wq_clients_show (struct device * dev ,
789792 struct device_attribute * attr , char * buf )
@@ -856,7 +859,7 @@ static ssize_t wq_group_id_store(struct device *dev,
856859 return count ;
857860 }
858861
859- group = & idxd -> groups [id ];
862+ group = idxd -> groups [id ];
860863 prevg = wq -> group ;
861864
862865 if (prevg )
@@ -1666,37 +1669,27 @@ static int idxd_register_engine_devices(struct idxd_device *idxd)
16661669 return rc ;
16671670}
16681671
1669- static int idxd_setup_group_sysfs (struct idxd_device * idxd )
1672+ static int idxd_register_group_devices (struct idxd_device * idxd )
16701673{
1671- struct device * dev = & idxd -> pdev -> dev ;
1672- int i , rc ;
1674+ int i , j , rc ;
16731675
16741676 for (i = 0 ; i < idxd -> max_groups ; i ++ ) {
1675- struct idxd_group * group = & idxd -> groups [i ];
1676-
1677- group -> conf_dev .parent = & idxd -> conf_dev ;
1678- dev_set_name (& group -> conf_dev , "group%d.%d" ,
1679- idxd -> id , group -> id );
1680- group -> conf_dev .bus = idxd_get_bus_type (idxd );
1681- group -> conf_dev .groups = idxd_group_attribute_groups ;
1682- group -> conf_dev .type = & idxd_group_device_type ;
1683- dev_dbg (dev , "Group device register: %s\n" ,
1684- dev_name (& group -> conf_dev ));
1685- rc = device_register (& group -> conf_dev );
1686- if (rc < 0 ) {
1687- put_device (& group -> conf_dev );
1677+ struct idxd_group * group = idxd -> groups [i ];
1678+
1679+ rc = device_add (& group -> conf_dev );
1680+ if (rc < 0 )
16881681 goto cleanup ;
1689- }
16901682 }
16911683
16921684 return 0 ;
16931685
16941686cleanup :
1695- while (i -- ) {
1696- struct idxd_group * group = & idxd -> groups [i ];
1687+ j = i - 1 ;
1688+ for (; i < idxd -> max_groups ; i ++ )
1689+ put_device (& idxd -> groups [i ]-> conf_dev );
16971690
1698- device_unregister ( & group -> conf_dev );
1699- }
1691+ while ( j -- )
1692+ device_unregister ( & idxd -> groups [ j ] -> conf_dev );
17001693 return rc ;
17011694}
17021695
@@ -1745,10 +1738,9 @@ int idxd_register_devices(struct idxd_device *idxd)
17451738 goto err_engine ;
17461739 }
17471740
1748- rc = idxd_setup_group_sysfs (idxd );
1741+ rc = idxd_register_group_devices (idxd );
17491742 if (rc < 0 ) {
1750- /* unregister conf dev */
1751- dev_dbg (dev , "Group sysfs registering failed: %d\n" , rc );
1743+ dev_dbg (dev , "Group device registering failed: %d\n" , rc );
17521744 goto err_group ;
17531745 }
17541746
@@ -1782,7 +1774,7 @@ void idxd_unregister_devices(struct idxd_device *idxd)
17821774 }
17831775
17841776 for (i = 0 ; i < idxd -> max_groups ; i ++ ) {
1785- struct idxd_group * group = & idxd -> groups [i ];
1777+ struct idxd_group * group = idxd -> groups [i ];
17861778
17871779 device_unregister (& group -> conf_dev );
17881780 }
0 commit comments