aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-21 16:47:50 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-21 19:02:19 -0400
commit3e9b2bae8369661070622d05570cbcdfa01770e6 (patch)
treea5e22d5953306740dca0da253752ad6830baaa50 /fs
parentfa2be40fe7c0aa3b7accbf6dfa9ef0976e191d4c (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>
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,
131} 131}
132 132
133/** 133/**
134 * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
135 * @kobj: The kobject to create the group on
136 * @groups: The attribute groups to create, NULL terminated
137 *
138 * This function creates a bunch of attribute groups. If an error occurs when
139 * creating a group, all previously created groups will be removed, unwinding
140 * everything back to the original state when this function was called.
141 * It will explicitly warn and error if any of the attribute files being
142 * created already exist.
143 *
144 * Returns 0 on success or error code from sysfs_create_groups on error.
145 */
146int sysfs_create_groups(struct kobject *kobj,
147 const struct attribute_group **groups)
148{
149 int error = 0;
150 int i;
151
152 if (!groups)
153 return 0;
154
155 for (i = 0; groups[i]; i++) {
156 error = sysfs_create_group(kobj, groups[i]);
157 if (error) {
158 while (--i >= 0)
159 sysfs_remove_group(kobj, groups[i]);
160 break;
161 }
162 }
163 return error;
164}
165EXPORT_SYMBOL_GPL(sysfs_create_groups);
166
167/**
134 * sysfs_update_group - given a directory kobject, update an attribute group 168 * sysfs_update_group - given a directory kobject, update an attribute group
135 * @kobj: The kobject to update the group on 169 * @kobj: The kobject to update the group on
136 * @grp: The attribute group to update 170 * @grp: The attribute group to update
@@ -179,6 +213,26 @@ void sysfs_remove_group(struct kobject * kobj,
179} 213}
180 214
181/** 215/**
216 * sysfs_remove_groups - remove a list of groups
217 *
218 * kobj: The kobject for the groups to be removed from
219 * groups: NULL terminated list of groups to be removed
220 *
221 * If groups is not NULL, the all groups will be removed from the kobject
222 */
223void sysfs_remove_groups(struct kobject *kobj,
224 const struct attribute_group **groups)
225{
226 int i;
227
228 if (!groups)
229 return;
230 for (i = 0; groups[i]; i++)
231 sysfs_remove_group(kobj, groups[i]);
232}
233EXPORT_SYMBOL_GPL(sysfs_remove_groups);
234
235/**
182 * sysfs_merge_group - merge files into a pre-existing attribute group. 236 * sysfs_merge_group - merge files into a pre-existing attribute group.
183 * @kobj: The kobject containing the group. 237 * @kobj: The kobject containing the group.
184 * @grp: The files to create and the attribute group they belong to. 238 * @grp: The files to create and the attribute group they belong to.