diff options
author | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-08-08 18:22:55 -0400 |
---|---|---|
committer | Nitin Garg <nitin.garg@freescale.com> | 2014-04-16 09:05:56 -0400 |
commit | 4ee122a685ab37955aa57bf1b58a49930398fd36 (patch) | |
tree | 5494c84f5e5e4c99b8878613326ae773255b257d | |
parent | bbfb188d6642386424860f9180d24a4acd75ab97 (diff) |
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>
Signed-off-by: Huang Shijie <b32955@freescale.com>
-rw-r--r-- | drivers/base/base.h | 5 | ||||
-rw-r--r-- | drivers/base/bus.c | 6 | ||||
-rw-r--r-- | drivers/base/core.c | 7 | ||||
-rw-r--r-- | include/linux/device.h | 4 |
4 files changed, 17 insertions, 5 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h index b8bdfe61daa6..fccf954f82fd 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -119,6 +119,11 @@ static inline int driver_match_device(struct device_driver *drv, | |||
119 | return drv->bus->match ? drv->bus->match(dev, drv) : 1; | 119 | return drv->bus->match ? drv->bus->match(dev, drv) : 1; |
120 | } | 120 | } |
121 | 121 | ||
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 | |||
122 | extern char *make_class_name(const char *name, struct kobject *kobj); | 127 | extern char *make_class_name(const char *name, struct kobject *kobj); |
123 | 128 | ||
124 | extern int devres_release_all(struct device *dev); | 129 | extern int devres_release_all(struct device *dev); |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index d414331b480e..7b2dc5ba7d79 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -499,6 +499,9 @@ int bus_add_device(struct device *dev) | |||
499 | error = device_add_attrs(bus, dev); | 499 | error = device_add_attrs(bus, dev); |
500 | if (error) | 500 | if (error) |
501 | goto out_put; | 501 | goto out_put; |
502 | error = device_add_groups(dev, bus->dev_groups); | ||
503 | if (error) | ||
504 | goto out_groups; | ||
502 | error = sysfs_create_link(&bus->p->devices_kset->kobj, | 505 | error = sysfs_create_link(&bus->p->devices_kset->kobj, |
503 | &dev->kobj, dev_name(dev)); | 506 | &dev->kobj, dev_name(dev)); |
504 | if (error) | 507 | if (error) |
@@ -513,6 +516,8 @@ int bus_add_device(struct device *dev) | |||
513 | 516 | ||
514 | out_subsys: | 517 | out_subsys: |
515 | sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); | 518 | sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); |
519 | out_groups: | ||
520 | device_remove_groups(dev, bus->dev_groups); | ||
516 | out_id: | 521 | out_id: |
517 | device_remove_attrs(bus, dev); | 522 | device_remove_attrs(bus, dev); |
518 | out_put: | 523 | out_put: |
@@ -575,6 +580,7 @@ void bus_remove_device(struct device *dev) | |||
575 | sysfs_remove_link(&dev->bus->p->devices_kset->kobj, | 580 | sysfs_remove_link(&dev->bus->p->devices_kset->kobj, |
576 | dev_name(dev)); | 581 | dev_name(dev)); |
577 | device_remove_attrs(dev->bus, dev); | 582 | device_remove_attrs(dev->bus, dev); |
583 | device_remove_groups(dev, dev->bus->dev_groups); | ||
578 | if (klist_node_attached(&dev->p->knode_bus)) | 584 | if (klist_node_attached(&dev->p->knode_bus)) |
579 | klist_del(&dev->p->knode_bus); | 585 | klist_del(&dev->p->knode_bus); |
580 | 586 | ||
diff --git a/drivers/base/core.c b/drivers/base/core.c index ca4bcb8b3938..e4bdf535fb27 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -461,8 +461,7 @@ static void device_remove_bin_attributes(struct device *dev, | |||
461 | device_remove_bin_file(dev, &attrs[i]); | 461 | device_remove_bin_file(dev, &attrs[i]); |
462 | } | 462 | } |
463 | 463 | ||
464 | static int device_add_groups(struct device *dev, | 464 | int device_add_groups(struct device *dev, const struct attribute_group **groups) |
465 | const struct attribute_group **groups) | ||
466 | { | 465 | { |
467 | int error = 0; | 466 | int error = 0; |
468 | int i; | 467 | int i; |
@@ -481,8 +480,8 @@ static int device_add_groups(struct device *dev, | |||
481 | return error; | 480 | return error; |
482 | } | 481 | } |
483 | 482 | ||
484 | static void device_remove_groups(struct device *dev, | 483 | void device_remove_groups(struct device *dev, |
485 | const struct attribute_group **groups) | 484 | const struct attribute_group **groups) |
486 | { | 485 | { |
487 | int i; | 486 | int i; |
488 | 487 | ||
diff --git a/include/linux/device.h b/include/linux/device.h index de1d2860fca5..9fdd6c8a1799 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -66,6 +66,7 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); | |||
66 | * @bus_attrs: Default attributes of the bus. | 66 | * @bus_attrs: Default attributes of the bus. |
67 | * @dev_attrs: Default attributes of the devices on the bus. | 67 | * @dev_attrs: Default attributes of the devices on the bus. |
68 | * @drv_attrs: Default attributes of the device drivers on the bus. | 68 | * @drv_attrs: Default attributes of the device drivers on the bus. |
69 | * @dev_groups: Default attributes of the devices on the bus. | ||
69 | * @match: Called, perhaps multiple times, whenever a new device or driver | 70 | * @match: Called, perhaps multiple times, whenever a new device or driver |
70 | * is added for this bus. It should return a nonzero value if the | 71 | * is added for this bus. It should return a nonzero value if the |
71 | * given device can be handled by the given driver. | 72 | * given device can be handled by the given driver. |
@@ -99,8 +100,9 @@ struct bus_type { | |||
99 | const char *dev_name; | 100 | const char *dev_name; |
100 | struct device *dev_root; | 101 | struct device *dev_root; |
101 | struct bus_attribute *bus_attrs; | 102 | struct bus_attribute *bus_attrs; |
102 | struct device_attribute *dev_attrs; | 103 | struct device_attribute *dev_attrs; /* use dev_groups instead */ |
103 | struct driver_attribute *drv_attrs; | 104 | struct driver_attribute *drv_attrs; |
105 | const struct attribute_group **dev_groups; | ||
104 | 106 | ||
105 | int (*match)(struct device *dev, struct device_driver *drv); | 107 | int (*match)(struct device *dev, struct device_driver *drv); |
106 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); | 108 | int (*uevent)(struct device *dev, struct kobj_uevent_env *env); |