aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:14 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:03 -0400
commitdfeb9fb0343363aadc3ee00a9347d120bc2a26b1 (patch)
treef9bbba921409d021da1730b8edc95614504583cd
parent93e3cd8270d036953120eca83610f95d3f7374c6 (diff)
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>
-rw-r--r--fs/sysfs/dir.c73
-rw-r--r--fs/sysfs/symlink.c27
2 files changed, 58 insertions, 42 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index f09626cc568a..b4c482461403 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -207,40 +207,53 @@ static int init_symlink(struct inode * inode)
207 return 0; 207 return 0;
208} 208}
209 209
210static int create_dir(struct kobject * k, struct dentry * p, 210static int create_dir(struct kobject *kobj, struct dentry *parent,
211 const char * n, struct dentry ** d) 211 const char *name, struct dentry **p_dentry)
212{ 212{
213 int error; 213 int error;
214 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; 214 umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO;
215 struct dentry *dentry;
216 struct sysfs_dirent *sd;
215 217
216 mutex_lock(&p->d_inode->i_mutex); 218 mutex_lock(&parent->d_inode->i_mutex);
217 *d = lookup_one_len(n, p, strlen(n)); 219
218 if (!IS_ERR(*d)) { 220 dentry = lookup_one_len(name, parent, strlen(name));
219 if (sysfs_dirent_exist(p->d_fsdata, n)) 221 if (IS_ERR(dentry)) {
220 error = -EEXIST; 222 error = PTR_ERR(dentry);
221 else 223 goto out_unlock;
222 error = sysfs_make_dirent(p->d_fsdata, *d, k, mode, 224 }
223 SYSFS_DIR); 225
224 if (!error) { 226 error = -EEXIST;
225 error = sysfs_create(*d, mode, init_dir); 227 if (sysfs_dirent_exist(parent->d_fsdata, name))
226 if (!error) { 228 goto out_dput;
227 inc_nlink(p->d_inode); 229
228 (*d)->d_op = &sysfs_dentry_ops; 230 error = sysfs_make_dirent(parent->d_fsdata, dentry, kobj, mode,
229 d_rehash(*d); 231 SYSFS_DIR);
230 } 232 if (error)
231 } 233 goto out_drop;
232 if (error && (error != -EEXIST)) { 234
233 struct sysfs_dirent *sd = (*d)->d_fsdata; 235 error = sysfs_create(dentry, mode, init_dir);
234 if (sd) { 236 if (error)
235 list_del_init(&sd->s_sibling); 237 goto out_sput;
236 sysfs_put(sd); 238
237 } 239 inc_nlink(parent->d_inode);
238 d_drop(*d); 240 dentry->d_op = &sysfs_dentry_ops;
239 } 241 d_rehash(dentry);
240 dput(*d); 242
241 } else 243 *p_dentry = dentry;
242 error = PTR_ERR(*d); 244 error = 0;
243 mutex_unlock(&p->d_inode->i_mutex); 245 goto out_dput;
246
247 out_sput:
248 sd = dentry->d_fsdata;
249 list_del_init(&sd->s_sibling);
250 sysfs_put(sd);
251 out_drop:
252 d_drop(dentry);
253 out_dput:
254 dput(dentry);
255 out_unlock:
256 mutex_unlock(&parent->d_inode->i_mutex);
244 return error; 257 return error;
245} 258}
246 259
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 7b9c5bfde920..b463f17f6638 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -49,30 +49,33 @@ static int sysfs_add_link(struct dentry * parent, const char * name, struct kobj
49{ 49{
50 struct sysfs_dirent * parent_sd = parent->d_fsdata; 50 struct sysfs_dirent * parent_sd = parent->d_fsdata;
51 struct sysfs_symlink * sl; 51 struct sysfs_symlink * sl;
52 int error = 0; 52 int error;
53 53
54 error = -ENOMEM; 54 error = -ENOMEM;
55 sl = kmalloc(sizeof(*sl), GFP_KERNEL); 55 sl = kzalloc(sizeof(*sl), GFP_KERNEL);
56 if (!sl) 56 if (!sl)
57 goto exit1; 57 goto err_out;
58 58
59 sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL); 59 sl->link_name = kmalloc(strlen(name) + 1, GFP_KERNEL);
60 if (!sl->link_name) 60 if (!sl->link_name)
61 goto exit2; 61 goto err_out;
62 62
63 strcpy(sl->link_name, name); 63 strcpy(sl->link_name, name);
64 sl->target_kobj = kobject_get(target); 64 sl->target_kobj = kobject_get(target);
65 65
66 error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO, 66 error = sysfs_make_dirent(parent_sd, NULL, sl, S_IFLNK|S_IRWXUGO,
67 SYSFS_KOBJ_LINK); 67 SYSFS_KOBJ_LINK);
68 if (!error) 68 if (error)
69 return 0; 69 goto err_out;
70 70
71 kobject_put(target); 71 return 0;
72 kfree(sl->link_name); 72
73exit2: 73 err_out:
74 kfree(sl); 74 if (sl) {
75exit1: 75 kobject_put(sl->target_kobj);
76 kfree(sl->link_name);
77 kfree(sl);
78 }
76 return error; 79 return error;
77} 80}
78 81