diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-11-15 15:57:07 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-11-16 17:02:00 -0500 |
commit | 045cac6b3b067a9286dabfb789f67ae4f433f88b (patch) | |
tree | b0cf5e7ce35503125a08a31b9ab8ce0a35868aa5 /drivers | |
parent | 63defa73c8c1193c1273474440c30d34c2524597 (diff) |
USB: use sysfs_merge_group for power attributes
This patch (as1426) makes use of the new sysfs_merge_group() and
sysfs_unmerge_group() routines to simplify the handling of power
attributes for USB devices.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/core/sysfs.c | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c index 448f5b47fc48..9561e087907d 100644 --- a/drivers/usb/core/sysfs.c +++ b/drivers/usb/core/sysfs.c | |||
@@ -233,8 +233,6 @@ static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL); | |||
233 | 233 | ||
234 | #ifdef CONFIG_PM | 234 | #ifdef CONFIG_PM |
235 | 235 | ||
236 | static const char power_group[] = "power"; | ||
237 | |||
238 | static ssize_t | 236 | static ssize_t |
239 | show_persist(struct device *dev, struct device_attribute *attr, char *buf) | 237 | show_persist(struct device *dev, struct device_attribute *attr, char *buf) |
240 | { | 238 | { |
@@ -278,7 +276,7 @@ static int add_persist_attributes(struct device *dev) | |||
278 | if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) | 276 | if (udev->descriptor.bDeviceClass != USB_CLASS_HUB) |
279 | rc = sysfs_add_file_to_group(&dev->kobj, | 277 | rc = sysfs_add_file_to_group(&dev->kobj, |
280 | &dev_attr_persist.attr, | 278 | &dev_attr_persist.attr, |
281 | power_group); | 279 | power_group_name); |
282 | } | 280 | } |
283 | return rc; | 281 | return rc; |
284 | } | 282 | } |
@@ -287,7 +285,7 @@ static void remove_persist_attributes(struct device *dev) | |||
287 | { | 285 | { |
288 | sysfs_remove_file_from_group(&dev->kobj, | 286 | sysfs_remove_file_from_group(&dev->kobj, |
289 | &dev_attr_persist.attr, | 287 | &dev_attr_persist.attr, |
290 | power_group); | 288 | power_group_name); |
291 | } | 289 | } |
292 | #else | 290 | #else |
293 | 291 | ||
@@ -438,44 +436,30 @@ set_level(struct device *dev, struct device_attribute *attr, | |||
438 | 436 | ||
439 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); | 437 | static DEVICE_ATTR(level, S_IRUGO | S_IWUSR, show_level, set_level); |
440 | 438 | ||
439 | static struct attribute *power_attrs[] = { | ||
440 | &dev_attr_autosuspend.attr, | ||
441 | &dev_attr_level.attr, | ||
442 | &dev_attr_connected_duration.attr, | ||
443 | &dev_attr_active_duration.attr, | ||
444 | NULL, | ||
445 | }; | ||
446 | static struct attribute_group power_attr_group = { | ||
447 | .name = power_group_name, | ||
448 | .attrs = power_attrs, | ||
449 | }; | ||
450 | |||
441 | static int add_power_attributes(struct device *dev) | 451 | static int add_power_attributes(struct device *dev) |
442 | { | 452 | { |
443 | int rc = 0; | 453 | int rc = 0; |
444 | 454 | ||
445 | if (is_usb_device(dev)) { | 455 | if (is_usb_device(dev)) |
446 | rc = sysfs_add_file_to_group(&dev->kobj, | 456 | rc = sysfs_merge_group(&dev->kobj, &power_attr_group); |
447 | &dev_attr_autosuspend.attr, | ||
448 | power_group); | ||
449 | if (rc == 0) | ||
450 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
451 | &dev_attr_level.attr, | ||
452 | power_group); | ||
453 | if (rc == 0) | ||
454 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
455 | &dev_attr_connected_duration.attr, | ||
456 | power_group); | ||
457 | if (rc == 0) | ||
458 | rc = sysfs_add_file_to_group(&dev->kobj, | ||
459 | &dev_attr_active_duration.attr, | ||
460 | power_group); | ||
461 | } | ||
462 | return rc; | 457 | return rc; |
463 | } | 458 | } |
464 | 459 | ||
465 | static void remove_power_attributes(struct device *dev) | 460 | static void remove_power_attributes(struct device *dev) |
466 | { | 461 | { |
467 | sysfs_remove_file_from_group(&dev->kobj, | 462 | sysfs_unmerge_group(&dev->kobj, &power_attr_group); |
468 | &dev_attr_active_duration.attr, | ||
469 | power_group); | ||
470 | sysfs_remove_file_from_group(&dev->kobj, | ||
471 | &dev_attr_connected_duration.attr, | ||
472 | power_group); | ||
473 | sysfs_remove_file_from_group(&dev->kobj, | ||
474 | &dev_attr_level.attr, | ||
475 | power_group); | ||
476 | sysfs_remove_file_from_group(&dev->kobj, | ||
477 | &dev_attr_autosuspend.attr, | ||
478 | power_group); | ||
479 | } | 463 | } |
480 | 464 | ||
481 | #else | 465 | #else |