aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-08 18:22:57 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-12 18:33:31 -0400
commit12478ba077adf8b53be6101b80dd8a65e4df9ea6 (patch)
tree7630f97c167d5dcc59cb6e517374d0e544c3f04e /drivers/base
parented0617b5c0bcd7fd04053568aa0cc19a977a1f26 (diff)
driver core: bus_type: add bus_groups
attribute groups are much more flexible than just a list of attributes, due to their support for visibility of the attributes, and binary attributes. Add bus_groups to struct bus_type which should be used instead of bus_attrs. bus_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/bus.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index de5ce22df306..5ee5d3c1d74b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -881,6 +881,37 @@ static void bus_remove_attrs(struct bus_type *bus)
881 } 881 }
882} 882}
883 883
884static int bus_add_groups(struct bus_type *bus,
885 const struct attribute_group **groups)
886{
887 int error = 0;
888 int i;
889
890 if (groups) {
891 for (i = 0; groups[i]; i++) {
892 error = sysfs_create_group(&bus->p->subsys.kobj,
893 groups[i]);
894 if (error) {
895 while (--i >= 0)
896 sysfs_remove_group(&bus->p->subsys.kobj,
897 groups[i]);
898 break;
899 }
900 }
901 }
902 return error;
903}
904
905static void bus_remove_groups(struct bus_type *bus,
906 const struct attribute_group **groups)
907{
908 int i;
909
910 if (groups)
911 for (i = 0; groups[i]; i++)
912 sysfs_remove_group(&bus->p->subsys.kobj, groups[i]);
913}
914
884static void klist_devices_get(struct klist_node *n) 915static void klist_devices_get(struct klist_node *n)
885{ 916{
886 struct device_private *dev_prv = to_device_private_bus(n); 917 struct device_private *dev_prv = to_device_private_bus(n);
@@ -973,10 +1004,15 @@ int bus_register(struct bus_type *bus)
973 retval = bus_add_attrs(bus); 1004 retval = bus_add_attrs(bus);
974 if (retval) 1005 if (retval)
975 goto bus_attrs_fail; 1006 goto bus_attrs_fail;
1007 retval = bus_add_groups(bus, bus->bus_groups);
1008 if (retval)
1009 goto bus_groups_fail;
976 1010
977 pr_debug("bus: '%s': registered\n", bus->name); 1011 pr_debug("bus: '%s': registered\n", bus->name);
978 return 0; 1012 return 0;
979 1013
1014bus_groups_fail:
1015 bus_remove_attrs(bus);
980bus_attrs_fail: 1016bus_attrs_fail:
981 remove_probe_files(bus); 1017 remove_probe_files(bus);
982bus_probe_files_fail: 1018bus_probe_files_fail:
@@ -1007,6 +1043,7 @@ void bus_unregister(struct bus_type *bus)
1007 if (bus->dev_root) 1043 if (bus->dev_root)
1008 device_unregister(bus->dev_root); 1044 device_unregister(bus->dev_root);
1009 bus_remove_attrs(bus); 1045 bus_remove_attrs(bus);
1046 bus_remove_groups(bus, bus->bus_groups);
1010 remove_probe_files(bus); 1047 remove_probe_files(bus);
1011 kset_unregister(bus->p->drivers_kset); 1048 kset_unregister(bus->p->drivers_kset);
1012 kset_unregister(bus->p->devices_kset); 1049 kset_unregister(bus->p->devices_kset);