Commit dfeb9fb0 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

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: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 93e3cd82
...@@ -207,40 +207,53 @@ static int init_symlink(struct inode * inode) ...@@ -207,40 +207,53 @@ static int init_symlink(struct inode * inode)
return 0; return 0;
} }
static int create_dir(struct kobject * k, struct dentry * p, static int create_dir(struct kobject *kobj, struct dentry *parent,
const char * n, struct dentry ** d) const char *name, struct dentry **p_dentry)
{ {
int error; int error;
umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
struct dentry *dentry;
struct sysfs_dirent *sd;
mutex_lock(&p->d_inode->i_mutex); mutex_lock(&parent->d_inode->i_mutex);
*d = lookup_one_len(n, p, strlen(n));
if (!IS_ERR(*d)) { dentry = lookup_one_len(name, parent, strlen(name));
if (sysfs_dirent_exist(p->d_fsdata, n)) if (IS_ERR(dentry)) {
error = -EEXIST; error = PTR_ERR(dentry);
else goto out_unlock;
error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, }
SYSFS_DIR);
if (!error) { error = -EEXIST;
error = sysfs_create(*d, mode, init_dir); if (sysfs_dirent_exist(parent->d_fsdata, name))
if (!error) { goto out_dput;
inc_nlink(p->d_inode);
(*d)->d_op = &sysfs_dentry_ops; error = sysfs_make_dirent(parent->d_fsdata, dentry, kobj, mode,
d_rehash(*d); SYSFS_DIR);
} if (error)
} goto out_drop;
if (error && (error != -EEXIST)) {
struct sysfs_dirent *sd = (*d)->d_fsdata; error = sysfs_create(dentry, mode, init_dir);
if (sd) { if (error)
list_del_init(&sd->s_sibling); goto out_sput;
sysfs_put(sd);
} inc_nlink(parent->d_inode);
d_drop(*d); dentry->d_op = &sysfs_dentry_ops;
} d_rehash(dentry);
dput(*d);
} else *p_dentry = dentry;
error = PTR_ERR(*d); error = 0;
mutex_unlock(&p->d_inode->i_mutex); goto out_dput;
out_sput:
sd = dentry->d_fsdata;
list_del_init(&sd->s_sibling);
sysfs_put(sd);
out_drop:
d_drop(dentry);
out_dput:
dput(dentry);
out_unlock:
mutex_unlock(&parent->d_inode->i_mutex);
return error; return error;
} }
......
...@@ -49,30 +49,33 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj ...@@ -49,30 +49,33 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj
{ {
struct sysfs_dirent * parent_sd = parent->d_fsdata; struct sysfs_dirent * parent_sd = parent->d_fsdata;
struct sysfs_symlink * sl; struct sysfs_symlink * sl;
int error = 0; int error;
error = -ENOMEM; error = -ENOMEM;
sl = kmalloc(sizeof(*sl), GFP_KERNEL); sl = kzalloc(sizeof(*sl), GFP_KERNEL);
if (!sl) if (!sl)
goto exit1; goto err_out;
sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL); sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL);
if (!sl->link_name) if (!sl->link_name)
goto exit2; goto err_out;
strcpy(sl->link_name, name); strcpy(sl->link_name, name);
sl->target_kobj = kobject_get(target); sl->target_kobj = kobject_get(target);
error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO, error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO,
SYSFS_KOBJ_LINK); SYSFS_KOBJ_LINK);
if (!error) if (error)
return 0; goto err_out;
kobject_put(target); return 0;
kfree(sl->link_name);
exit2: err_out:
kfree(sl); if (sl) {
exit1: kobject_put(sl->target_kobj);
kfree(sl->link_name);
kfree(sl);
}
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment