Skip to content

Commit fa6fdb3

Browse files
committed
driver core: bus_type: add dev_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 dev_groups to struct bus_type which should be used instead of dev_attrs. dev_attrs will be removed from the structure soon. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e70b091 commit fa6fdb3

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎drivers/base/base.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv,
119119
return drv->bus->match ? drv->bus->match(dev, drv) : 1;
120120
}
121121

122+
extern int device_add_groups(struct device *dev,
123+
const struct attribute_group **groups);
124+
extern void device_remove_groups(struct device *dev,
125+
const struct attribute_group **groups);
126+
122127
extern char *make_class_name(const char *name, struct kobject *kobj);
123128

124129
extern int devres_release_all(struct device *dev);

‎drivers/base/bus.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ int bus_add_device(struct device *dev)
499499
error = device_add_attrs(bus, dev);
500500
if (error)
501501
goto out_put;
502+
error = device_add_groups(dev, bus->dev_groups);
503+
if (error)
504+
goto out_groups;
502505
error = sysfs_create_link(&bus->p->devices_kset->kobj,
503506
&dev->kobj, dev_name(dev));
504507
if (error)
@@ -513,6 +516,8 @@ int bus_add_device(struct device *dev)
513516

514517
out_subsys:
515518
sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev));
519+
out_groups:
520+
device_remove_groups(dev, bus->dev_groups);
516521
out_id:
517522
device_remove_attrs(bus, dev);
518523
out_put:
@@ -575,6 +580,7 @@ void bus_remove_device(struct device *dev)
575580
sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
576581
dev_name(dev));
577582
device_remove_attrs(dev->bus, dev);
583+
device_remove_groups(dev, dev->bus->dev_groups);
578584
if (klist_node_attached(&dev->p->knode_bus))
579585
klist_del(&dev->p->knode_bus);
580586

‎drivers/base/core.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ static void device_remove_bin_attributes(struct device *dev,
491491
device_remove_bin_file(dev, &attrs[i]);
492492
}
493493

494-
static int device_add_groups(struct device *dev,
495-
const struct attribute_group **groups)
494+
int device_add_groups(struct device *dev, const struct attribute_group **groups)
496495
{
497496
int error = 0;
498497
int i;
@@ -511,8 +510,8 @@ static int device_add_groups(struct device *dev,
511510
return error;
512511
}
513512

514-
static void device_remove_groups(struct device *dev,
515-
const struct attribute_group **groups)
513+
void device_remove_groups(struct device *dev,
514+
const struct attribute_group **groups)
516515
{
517516
int i;
518517

‎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+
* @dev_groups: Default attributes of the devices on the bus.
6970
* @match: Called, perhaps multiple times, whenever a new device or driver
7071
* is added for this bus. It should return a nonzero value if the
7172
* given device can be handled by the given driver.
@@ -104,8 +105,9 @@ struct bus_type {
104105
const char *dev_name;
105106
struct device *dev_root;
106107
struct bus_attribute *bus_attrs;
107-
struct device_attribute *dev_attrs;
108+
struct device_attribute *dev_attrs; /* use dev_groups instead */
108109
struct driver_attribute *drv_attrs;
110+
const struct attribute_group **dev_groups;
109111

110112
int (*match)(struct device *dev, struct device_driver *drv);
111113
int (*uevent)(struct device *dev, struct kobj_uevent_env *env);

0 commit comments

Comments
 (0)