Skip to content

Commit 12478ba

Browse files
committed
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>
1 parent ed0617b commit 12478ba

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎drivers/base/bus.c‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,37 @@ static void bus_remove_attrs(struct bus_type *bus)
881881
}
882882
}
883883

884+
static 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+
905+
static 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+
884915
static void klist_devices_get(struct klist_node *n)
885916
{
886917
struct device_private *dev_prv = to_device_private_bus(n);
@@ -973,10 +1004,15 @@ int bus_register(struct bus_type *bus)
9731004
retval = bus_add_attrs(bus);
9741005
if (retval)
9751006
goto bus_attrs_fail;
1007+
retval = bus_add_groups(bus, bus->bus_groups);
1008+
if (retval)
1009+
goto bus_groups_fail;
9761010

9771011
pr_debug("bus: '%s': registered\n", bus->name);
9781012
return 0;
9791013

1014+
bus_groups_fail:
1015+
bus_remove_attrs(bus);
9801016
bus_attrs_fail:
9811017
remove_probe_files(bus);
9821018
bus_probe_files_fail:
@@ -1007,6 +1043,7 @@ void bus_unregister(struct bus_type *bus)
10071043
if (bus->dev_root)
10081044
device_unregister(bus->dev_root);
10091045
bus_remove_attrs(bus);
1046+
bus_remove_groups(bus, bus->bus_groups);
10101047
remove_probe_files(bus);
10111048
kset_unregister(bus->p->drivers_kset);
10121049
kset_unregister(bus->p->devices_kset);

‎include/linux/device.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
6666
* @bus_attrs: Default attributes of the bus.
6767
* @dev_attrs: Default attributes of the devices on the bus.
6868
* @drv_attrs: Default attributes of the device drivers on the bus.
69+
* @bus_groups: Default attributes of the bus.
6970
* @dev_groups: Default attributes of the devices on the bus.
7071
* @drv_groups: Default attributes of the device drivers on the bus.
7172
* @match: Called, perhaps multiple times, whenever a new device or driver
@@ -105,9 +106,10 @@ struct bus_type {
105106
const char *name;
106107
const char *dev_name;
107108
struct device *dev_root;
108-
struct bus_attribute *bus_attrs;
109+
struct bus_attribute *bus_attrs; /* use bus_groups instead */
109110
struct device_attribute *dev_attrs; /* use dev_groups instead */
110111
struct driver_attribute *drv_attrs; /* use drv_groups instead */
112+
const struct attribute_group **bus_groups;
111113
const struct attribute_group **dev_groups;
112114
const struct attribute_group **drv_groups;
113115

0 commit comments

Comments
 (0)