sysfs: flatten cleanup paths in sysfs_add_link() and create_dir()
Flatten cleanup paths in sysfs_add_link() and create_dir() to improve
readability and ease further changes to these functions. This is in
preparation of object reference simplification.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 7b9c5bf..b463f17 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -49,30 +49,33 @@
{
struct sysfs_dirent * parent_sd = parent->d_fsdata;
struct sysfs_symlink * sl;
- int error = 0;
+ int error;
error = -ENOMEM;
- sl = kmalloc(sizeof(*sl), GFP_KERNEL);
+ sl = kzalloc(sizeof(*sl), GFP_KERNEL);
if (!sl)
- goto exit1;
+ goto err_out;
sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL);
if (!sl->link_name)
- goto exit2;
+ goto err_out;
strcpy(sl->link_name, name);
sl->target_kobj = kobject_get(target);
error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO,
SYSFS_KOBJ_LINK);
- if (!error)
- return 0;
+ if (error)
+ goto err_out;
- kobject_put(target);
- kfree(sl->link_name);
-exit2:
- kfree(sl);
-exit1:
+ return 0;
+
+ err_out:
+ if (sl) {
+ kobject_put(sl->target_kobj);
+ kfree(sl->link_name);
+ kfree(sl);
+ }
return error;
}