Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

configfs: factor dirent removal into helpers

Lots of duplicated code that benefits from a little consolidation.

Signed-off-by: Christoph Hellwig <hch@lst.de>

+33 -30
+33 -30
fs/configfs/dir.c
··· 253 253 return 0; 254 254 } 255 255 256 + static void configfs_remove_dirent(struct dentry *dentry) 257 + { 258 + struct configfs_dirent *sd = dentry->d_fsdata; 259 + 260 + if (!sd) 261 + return; 262 + spin_lock(&configfs_dirent_lock); 263 + list_del_init(&sd->s_sibling); 264 + spin_unlock(&configfs_dirent_lock); 265 + configfs_put(sd); 266 + } 267 + 256 268 static void init_dir(struct inode * inode) 257 269 { 258 270 inode->i_op = &configfs_dir_inode_operations; ··· 321 309 322 310 configfs_set_dir_dirent_depth(p->d_fsdata, dentry->d_fsdata); 323 311 error = configfs_create(dentry, mode, init_dir); 324 - if (!error) { 325 - inc_nlink(d_inode(p)); 326 - item->ci_dentry = dentry; 327 - } else { 328 - struct configfs_dirent *sd = dentry->d_fsdata; 329 - if (sd) { 330 - spin_lock(&configfs_dirent_lock); 331 - list_del_init(&sd->s_sibling); 332 - spin_unlock(&configfs_dirent_lock); 333 - configfs_put(sd); 334 - } 335 - } 312 + if (error) 313 + goto out_remove; 314 + 315 + inc_nlink(d_inode(p)); 316 + item->ci_dentry = dentry; 317 + return 0; 318 + 319 + out_remove: 320 + configfs_remove_dirent(dentry); 336 321 return error; 337 322 } 338 323 ··· 381 372 382 373 err = configfs_make_dirent(p, dentry, sl, mode, 383 374 CONFIGFS_ITEM_LINK, p->s_frag); 384 - if (!err) { 385 - err = configfs_create(dentry, mode, init_symlink); 386 - if (err) { 387 - struct configfs_dirent *sd = dentry->d_fsdata; 388 - if (sd) { 389 - spin_lock(&configfs_dirent_lock); 390 - list_del_init(&sd->s_sibling); 391 - spin_unlock(&configfs_dirent_lock); 392 - configfs_put(sd); 393 - } 394 - } 395 - } 375 + if (err) 376 + return err; 377 + 378 + err = configfs_create(dentry, mode, init_symlink); 379 + if (err) 380 + goto out_remove; 381 + return 0; 382 + 383 + out_remove: 384 + configfs_remove_dirent(dentry); 396 385 return err; 397 386 } 398 387 399 388 static void remove_dir(struct dentry * d) 400 389 { 401 390 struct dentry * parent = dget(d->d_parent); 402 - struct configfs_dirent * sd; 403 391 404 - sd = d->d_fsdata; 405 - spin_lock(&configfs_dirent_lock); 406 - list_del_init(&sd->s_sibling); 407 - spin_unlock(&configfs_dirent_lock); 408 - configfs_put(sd); 392 + configfs_remove_dirent(d); 393 + 409 394 if (d_really_is_positive(d)) 410 395 simple_rmdir(d_inode(parent),d); 411 396