[PATCH 3/10] sysfs: fix error handling in create_files()

Akinobu Mita
2007-07-16T14:04:45Z

Current error handling in create_files() attempts to remove
all attributes passed by argument by remove_files(). But it should
only remove the attributes that have been successfully added.

Cc: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

---
fs/sysfs/group.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

Index: 2.6-mm/fs/sysfs/group.c
===================================================================
--- 2.6-mm.orig/fs/sysfs/group.c
+++ 2.6-mm/fs/sysfs/group.c
@@ -30,13 +30,19 @@ static void remove_files(struct sysfs_di
static int create_files(struct sysfs_dirent *dir_sd,
const struct attribute_group *grp)
{
- struct attribute *const* attr;
- int error = 0;
+ int i;
+ int error;
+
+ for (i = 0; grp->attrs[i]; i++) {
+ error = sysfs_add_file(dir_sd, grp->attrs[i], SYSFS_KOBJ_ATTR);
+ if (error)
+ goto error;
+ }
+ return 0;
+error:
+ while (i--)
+ sysfs_hash_and_remove(dir_sd, grp->attrs[i]->name);

- for (attr = grp->attrs; *attr && !error; attr++)
- error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR);
- if (error)
- remove_files(dir_sd, grp);
return error;
}