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

From: Akinobu Mita
Date: Mon Jul 16 2007 - 10:04:45 EST


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@xxxxxxx>
Signed-off-by: Akinobu Mita <akinobu.mita@xxxxxxxxx>

---
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;
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/