@@ -16,51 +16,26 @@ static char *idxd_wq_type_names[] = {
1616 [IDXD_WQT_USER ] = "user" ,
1717};
1818
19- static void idxd_conf_device_release (struct device * dev )
19+ static void idxd_conf_sub_device_release (struct device * dev )
2020{
2121 dev_dbg (dev , "%s for %s\n" , __func__ , dev_name (dev ));
2222}
2323
2424static struct device_type idxd_group_device_type = {
2525 .name = "group" ,
26- .release = idxd_conf_device_release ,
26+ .release = idxd_conf_sub_device_release ,
2727};
2828
2929static struct device_type idxd_wq_device_type = {
3030 .name = "wq" ,
31- .release = idxd_conf_device_release ,
31+ .release = idxd_conf_sub_device_release ,
3232};
3333
3434static struct device_type idxd_engine_device_type = {
3535 .name = "engine" ,
36- .release = idxd_conf_device_release ,
36+ .release = idxd_conf_sub_device_release ,
3737};
3838
39- static struct device_type dsa_device_type = {
40- .name = "dsa" ,
41- .release = idxd_conf_device_release ,
42- };
43-
44- static struct device_type iax_device_type = {
45- .name = "iax" ,
46- .release = idxd_conf_device_release ,
47- };
48-
49- static inline bool is_dsa_dev (struct device * dev )
50- {
51- return dev ? dev -> type == & dsa_device_type : false;
52- }
53-
54- static inline bool is_iax_dev (struct device * dev )
55- {
56- return dev ? dev -> type == & iax_device_type : false;
57- }
58-
59- static inline bool is_idxd_dev (struct device * dev )
60- {
61- return is_dsa_dev (dev ) || is_iax_dev (dev );
62- }
63-
6439static inline bool is_idxd_wq_dev (struct device * dev )
6540{
6641 return dev ? dev -> type == & idxd_wq_device_type : false;
@@ -405,7 +380,7 @@ struct bus_type *idxd_get_bus_type(struct idxd_device *idxd)
405380 return idxd_bus_types [idxd -> type ];
406381}
407382
408- static struct device_type * idxd_get_device_type (struct idxd_device * idxd )
383+ struct device_type * idxd_get_device_type (struct idxd_device * idxd )
409384{
410385 if (idxd -> type == IDXD_TYPE_DSA )
411386 return & dsa_device_type ;
@@ -1644,6 +1619,30 @@ static const struct attribute_group *idxd_attribute_groups[] = {
16441619 NULL ,
16451620};
16461621
1622+ static void idxd_conf_device_release (struct device * dev )
1623+ {
1624+ struct idxd_device * idxd = container_of (dev , struct idxd_device , conf_dev );
1625+
1626+ kfree (idxd -> groups );
1627+ kfree (idxd -> wqs );
1628+ kfree (idxd -> engines );
1629+ kfree (idxd -> irq_entries );
1630+ ida_free (idxd_ida (idxd ), idxd -> id );
1631+ kfree (idxd );
1632+ }
1633+
1634+ struct device_type dsa_device_type = {
1635+ .name = "dsa" ,
1636+ .release = idxd_conf_device_release ,
1637+ .groups = idxd_attribute_groups ,
1638+ };
1639+
1640+ struct device_type iax_device_type = {
1641+ .name = "iax" ,
1642+ .release = idxd_conf_device_release ,
1643+ .groups = idxd_attribute_groups ,
1644+ };
1645+
16471646static int idxd_setup_engine_sysfs (struct idxd_device * idxd )
16481647{
16491648 struct device * dev = & idxd -> pdev -> dev ;
@@ -1745,39 +1744,14 @@ static int idxd_setup_wq_sysfs(struct idxd_device *idxd)
17451744 return rc ;
17461745}
17471746
1748- static int idxd_setup_device_sysfs (struct idxd_device * idxd )
1747+ int idxd_register_devices (struct idxd_device * idxd )
17491748{
17501749 struct device * dev = & idxd -> pdev -> dev ;
17511750 int rc ;
1752- char devname [IDXD_NAME_SIZE ];
17531751
1754- sprintf (devname , "%s%d" , idxd_get_dev_name (idxd ), idxd -> id );
1755- idxd -> conf_dev .parent = dev ;
1756- dev_set_name (& idxd -> conf_dev , "%s" , devname );
1757- idxd -> conf_dev .bus = idxd_get_bus_type (idxd );
1758- idxd -> conf_dev .groups = idxd_attribute_groups ;
1759- idxd -> conf_dev .type = idxd_get_device_type (idxd );
1760-
1761- dev_dbg (dev , "IDXD device register: %s\n" , dev_name (& idxd -> conf_dev ));
1762- rc = device_register (& idxd -> conf_dev );
1763- if (rc < 0 ) {
1764- put_device (& idxd -> conf_dev );
1765- return rc ;
1766- }
1767-
1768- return 0 ;
1769- }
1770-
1771- int idxd_setup_sysfs (struct idxd_device * idxd )
1772- {
1773- struct device * dev = & idxd -> pdev -> dev ;
1774- int rc ;
1775-
1776- rc = idxd_setup_device_sysfs (idxd );
1777- if (rc < 0 ) {
1778- dev_dbg (dev , "Device sysfs registering failed: %d\n" , rc );
1752+ rc = device_add (& idxd -> conf_dev );
1753+ if (rc < 0 )
17791754 return rc ;
1780- }
17811755
17821756 rc = idxd_setup_wq_sysfs (idxd );
17831757 if (rc < 0 ) {
@@ -1803,7 +1777,7 @@ int idxd_setup_sysfs(struct idxd_device *idxd)
18031777 return 0 ;
18041778}
18051779
1806- void idxd_cleanup_sysfs (struct idxd_device * idxd )
1780+ void idxd_unregister_devices (struct idxd_device * idxd )
18071781{
18081782 int i ;
18091783
0 commit comments