diff options
author | Andi Kleen <andi@firstfloor.org> | 2010-01-05 06:48:01 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-07 20:04:47 -0500 |
commit | 1c205ae18db53ff72985dd79f3baaf2dbaba6db7 (patch) | |
tree | ba2947326f34337b33c90391496b6e40089bc2ad /fs/sysfs/file.c | |
parent | 265d2e2e31c5f6dc1b20ae1653a17fdba706f79e (diff) |
sysfs: Add sysfs_add/remove_files utility functions
Adding/Removing a whole array of attributes is very common. Add a standard
utility function to do this with a simple function call, instead of
requiring drivers to open code this.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index dc30d9e31683..50b725bcc3f3 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -542,6 +542,18 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr) | |||
542 | 542 | ||
543 | } | 543 | } |
544 | 544 | ||
545 | int sysfs_create_files(struct kobject *kobj, const struct attribute **ptr) | ||
546 | { | ||
547 | int err = 0; | ||
548 | int i; | ||
549 | |||
550 | for (i = 0; ptr[i] && !err; i++) | ||
551 | err = sysfs_create_file(kobj, ptr[i]); | ||
552 | if (err) | ||
553 | while (--i >= 0) | ||
554 | sysfs_remove_file(kobj, ptr[i]); | ||
555 | return err; | ||
556 | } | ||
545 | 557 | ||
546 | /** | 558 | /** |
547 | * sysfs_add_file_to_group - add an attribute file to a pre-existing group. | 559 | * sysfs_add_file_to_group - add an attribute file to a pre-existing group. |
@@ -614,6 +626,12 @@ void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr) | |||
614 | sysfs_hash_and_remove(kobj->sd, attr->name); | 626 | sysfs_hash_and_remove(kobj->sd, attr->name); |
615 | } | 627 | } |
616 | 628 | ||
629 | void sysfs_remove_files(struct kobject * kobj, const struct attribute **ptr) | ||
630 | { | ||
631 | int i; | ||
632 | for (i = 0; ptr[i]; i++) | ||
633 | sysfs_remove_file(kobj, ptr[i]); | ||
634 | } | ||
617 | 635 | ||
618 | /** | 636 | /** |
619 | * sysfs_remove_file_from_group - remove an attribute file from a group. | 637 | * sysfs_remove_file_from_group - remove an attribute file from a group. |
@@ -732,3 +750,5 @@ EXPORT_SYMBOL_GPL(sysfs_schedule_callback); | |||
732 | 750 | ||
733 | EXPORT_SYMBOL_GPL(sysfs_create_file); | 751 | EXPORT_SYMBOL_GPL(sysfs_create_file); |
734 | EXPORT_SYMBOL_GPL(sysfs_remove_file); | 752 | EXPORT_SYMBOL_GPL(sysfs_remove_file); |
753 | EXPORT_SYMBOL_GPL(sysfs_remove_files); | ||
754 | EXPORT_SYMBOL_GPL(sysfs_create_files); | ||