From 3e9b2bae8369661070622d05570cbcdfa01770e6 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 13:47:50 -0700 Subject: 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 --- fs/sysfs/group.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 09a1a25cd14..68baf850155 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -130,6 +130,40 @@ int sysfs_create_group(struct kobject *kobj, return internal_create_group(kobj, 0, grp); } +/** + * 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 @@ -178,6 +212,26 @@ void sysfs_remove_group(struct kobject * kobj, sysfs_put(sd); } +/** + * 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. -- cgit v1.2.3-70-g09d2 From d363bc53ef4233e02d70791f10fe1f18c6c0f508 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:04:12 -0700 Subject: sysfs: group.c: move EXPORT_SYMBOL_GPL() to the proper location This fixes up the coding style issue of incorrectly placing the EXPORT_SYMBOL_GPL() macro, it should be right after the function itself, not at the end of the file. Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 68baf850155..c86a1729f53 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -129,6 +129,7 @@ int sysfs_create_group(struct kobject *kobj, { return internal_create_group(kobj, 0, grp); } +EXPORT_SYMBOL_GPL(sysfs_create_group); /** * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups @@ -186,8 +187,7 @@ int sysfs_update_group(struct kobject *kobj, { return internal_create_group(kobj, 1, grp); } - - +EXPORT_SYMBOL_GPL(sysfs_update_group); void sysfs_remove_group(struct kobject * kobj, const struct attribute_group * grp) @@ -211,6 +211,7 @@ void sysfs_remove_group(struct kobject * kobj, sysfs_put(sd); } +EXPORT_SYMBOL_GPL(sysfs_remove_group); /** * sysfs_remove_groups - remove a list of groups @@ -327,7 +328,3 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, } } EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); - -EXPORT_SYMBOL_GPL(sysfs_create_group); -EXPORT_SYMBOL_GPL(sysfs_update_group); -EXPORT_SYMBOL_GPL(sysfs_remove_group); -- cgit v1.2.3-70-g09d2 From e6c56920fd81f804910360cd487ec78b766b3aa8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:06:14 -0700 Subject: sysfs: group.c: fix trailing whitespace There was some trailing spaces in the file, fix that up. Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index c86a1729f53..14672e9b917 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -4,7 +4,7 @@ * Copyright (c) 2003 Patrick Mochel * Copyright (c) 2003 Open Source Development Lab * - * This file is released undert the GPL v2. + * This file is released undert the GPL v2. * */ @@ -189,7 +189,7 @@ int sysfs_update_group(struct kobject *kobj, } EXPORT_SYMBOL_GPL(sysfs_update_group); -void sysfs_remove_group(struct kobject * kobj, +void sysfs_remove_group(struct kobject * kobj, const struct attribute_group * grp) { struct sysfs_dirent *dir_sd = kobj->sd; -- cgit v1.2.3-70-g09d2 From 995d8ed943291d2fa1174f5b00d8921c6cf91c98 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:07:29 -0700 Subject: sysfs: group.c: fix up some * coding style issues This fixes up the * coding style warnings for the group.c sysfs file. Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 14672e9b917..f4a9d221cbe 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -19,8 +19,8 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, const struct attribute_group *grp) { - struct attribute *const* attr; - struct bin_attribute *const* bin_attr; + struct attribute *const *attr; + struct bin_attribute *const *bin_attr; if (grp->attrs) for (attr = grp->attrs; *attr; attr++) @@ -33,8 +33,8 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, const struct attribute_group *grp, int update) { - struct attribute *const* attr; - struct bin_attribute *const* bin_attr; + struct attribute *const *attr; + struct bin_attribute *const *bin_attr; int error = 0, i; if (grp->attrs) { @@ -189,8 +189,8 @@ int sysfs_update_group(struct kobject *kobj, } EXPORT_SYMBOL_GPL(sysfs_update_group); -void sysfs_remove_group(struct kobject * kobj, - const struct attribute_group * grp) +void sysfs_remove_group(struct kobject *kobj, + const struct attribute_group *grp) { struct sysfs_dirent *dir_sd = kobj->sd; struct sysfs_dirent *sd; -- cgit v1.2.3-70-g09d2 From 16aebf1c5d30701c3e2733d0c1a0ee3236fd9eec Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:10:02 -0700 Subject: sysfs: group.c: fix up broken string coding style checkpatch complains about the broken string in the file, and it's correct, so fix it up. Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index f4a9d221cbe..642700131dd 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -198,8 +198,9 @@ void sysfs_remove_group(struct kobject *kobj, if (grp->name) { sd = sysfs_get_dirent(dir_sd, NULL, grp->name); if (!sd) { - WARN(!sd, KERN_WARNING "sysfs group %p not found for " - "kobject '%s'\n", grp, kobject_name(kobj)); + WARN(!sd, KERN_WARNING + "sysfs group %p not found for kobject '%s'\n", + grp, kobject_name(kobj)); return; } } else -- cgit v1.2.3-70-g09d2 From f9ae443b5a1aa3d34d57df966a220a51a854d4c8 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:12:34 -0700 Subject: sysfs: group.c: add kerneldoc for sysfs_remove_group sysfs_remove_group() never had kerneldoc, so add it, and fix up the kerneldoc for sysfs_remove_groups() which didn't specify the parameters properly. Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 642700131dd..4633b20b6ec 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -189,6 +189,14 @@ int sysfs_update_group(struct kobject *kobj, } EXPORT_SYMBOL_GPL(sysfs_update_group); +/** + * sysfs_remove_group: remove a group from a kobject + * @kobj: kobject to remove the group from + * @grp: group to remove + * + * This function removes a group of attributes from a kobject. The attributes + * previously have to have been created for this group, otherwise it will fail. + */ void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp) { @@ -217,8 +225,8 @@ EXPORT_SYMBOL_GPL(sysfs_remove_group); /** * 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 + * @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 */ -- cgit v1.2.3-70-g09d2 From 9e2a47ed6443b7af1e5b91f59e8738c01fde45a9 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 21 Aug 2013 16:14:11 -0700 Subject: sysfs: group: update copyright to add myself and the LF Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 4633b20b6ec..cb987e6c927 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -3,6 +3,8 @@ * * Copyright (c) 2003 Patrick Mochel * Copyright (c) 2003 Open Source Development Lab + * Copyright (c) 2013 Greg Kroah-Hartman + * Copyright (c) 2013 The Linux Foundation * * This file is released undert the GPL v2. * -- cgit v1.2.3-70-g09d2 From 09239ed4aa99b2d2fd9b1a51b264661a4a6d469e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 22 Aug 2013 09:23:28 -0700 Subject: sysfs: group.c: fix up kerneldoc Fix up the wording of sysfs_create/remove_groups() a bit. Reported-by: Anthony Foiani Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/group.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fs/sysfs/group.c') diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index cb987e6c927..5f92cd2f61c 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -144,7 +144,7 @@ EXPORT_SYMBOL_GPL(sysfs_create_group); * 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. + * Returns 0 on success or error code from sysfs_create_group on error. */ int sysfs_create_groups(struct kobject *kobj, const struct attribute_group **groups) @@ -230,7 +230,7 @@ EXPORT_SYMBOL_GPL(sysfs_remove_group); * @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 + * If groups is not NULL, remove the specified groups from the kobject. */ void sysfs_remove_groups(struct kobject *kobj, const struct attribute_group **groups) -- cgit v1.2.3-70-g09d2