summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-21 13:47:50 -0700
committerRichard Zhu <Richard.Zhu@freescale.com>2014-11-07 12:57:44 +0800
commit0e1c09e27232f3554925eb1a7edc0da263e3b0b6 (patch)
treee1e0952cfb7ae76ea13fe2865601f9034eed5780 /fs
parent73a409b03c3af42fe17adc774c569439b85b50cf (diff)
sysfs: add sysfs_create/remove_groups()
These functions are being open-coded in 3 different places in the driver core, and other driver subsystems will want to start doing this as well, so move it to the sysfs core to keep it all in one place, where we know it is written properly. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Conflicts: drivers/base/bus.c (cherry picked from commit f1986282fe78586eddf3ae972a72eab7ca425aa7)
Diffstat (limited to 'fs')
-rw-r--r--fs/sysfs/group.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 09a1a25cd145..68baf8501552 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -131,6 +131,40 @@ int sysfs_create_group(struct kobject *kobj,
}
/**
+ * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
+ * @kobj: The kobject to create the group on
+ * @groups: The attribute groups to create, NULL terminated
+ *
+ * This function creates a bunch of attribute groups. If an error occurs when
+ * creating a group, all previously created groups will be removed, unwinding
+ * everything back to the original state when this function was called.
+ * It will explicitly warn and error if any of the attribute files being
+ * created already exist.
+ *
+ * Returns 0 on success or error code from sysfs_create_groups on error.
+ */
+int sysfs_create_groups(struct kobject *kobj,
+ const struct attribute_group **groups)
+{
+ int error = 0;
+ int i;
+
+ if (!groups)
+ return 0;
+
+ for (i = 0; groups[i]; i++) {
+ error = sysfs_create_group(kobj, groups[i]);
+ if (error) {
+ while (--i >= 0)
+ sysfs_remove_group(kobj, groups[i]);
+ break;
+ }
+ }
+ return error;
+}
+EXPORT_SYMBOL_GPL(sysfs_create_groups);
+
+/**
* sysfs_update_group - given a directory kobject, update an attribute group
* @kobj: The kobject to update the group on
* @grp: The attribute group to update
@@ -179,6 +213,26 @@ void sysfs_remove_group(struct kobject * kobj,
}
/**
+ * sysfs_remove_groups - remove a list of groups
+ *
+ * kobj: The kobject for the groups to be removed from
+ * groups: NULL terminated list of groups to be removed
+ *
+ * If groups is not NULL, the all groups will be removed from the kobject
+ */
+void sysfs_remove_groups(struct kobject *kobj,
+ const struct attribute_group **groups)
+{
+ int i;
+
+ if (!groups)
+ return;
+ for (i = 0; groups[i]; i++)
+ sysfs_remove_group(kobj, groups[i]);
+}
+EXPORT_SYMBOL_GPL(sysfs_remove_groups);
+
+/**
* sysfs_merge_group - merge files into a pre-existing attribute group.
* @kobj: The kobject containing the group.
* @grp: The files to create and the attribute group they belong to.