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

sysfs: use ilookup5() instead of ilookup5_nowait()

As inode creation is protected by sysfs_mutex, ilookup5_nowait()
always either fails to find at all or finds one which is fully
initialized, so using ilookup5_nowait() or ilookup5() doesn't make any
difference. Switch to ilookup5() as it's planned to be removed. This
change also makes lookup return value handling a bit simpler.

This change was suggested by Al Viro.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Al Viro <viro@hera.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Tejun Heo and committed by
Greg Kroah-Hartman
45c076c5 8a89efd1

+8 -9
+8 -9
fs/sysfs/dir.c
··· 370 370 memset(acxt, 0, sizeof(*acxt)); 371 371 acxt->parent_sd = parent_sd; 372 372 373 - /* Lookup parent inode. inode initialization and I_NEW 374 - * clearing are protected by sysfs_mutex. By grabbing it and 375 - * looking up with _nowait variant, inode state can be 376 - * determined reliably. 373 + /* Lookup parent inode. inode initialization is protected by 374 + * sysfs_mutex, so inode existence can be determined by 375 + * looking up inode while holding sysfs_mutex. 377 376 */ 378 377 mutex_lock(&sysfs_mutex); 379 378 380 - inode = ilookup5_nowait(sysfs_sb, parent_sd->s_ino, sysfs_ilookup_test, 381 - parent_sd); 379 + inode = ilookup5(sysfs_sb, parent_sd->s_ino, sysfs_ilookup_test, 380 + parent_sd); 381 + if (inode) { 382 + WARN_ON(inode->i_state & I_NEW); 382 383 383 - if (inode && !(inode->i_state & I_NEW)) { 384 384 /* parent inode available */ 385 385 acxt->parent_inode = inode; 386 386 ··· 393 393 mutex_lock(&inode->i_mutex); 394 394 mutex_lock(&sysfs_mutex); 395 395 } 396 - } else 397 - iput(inode); 396 + } 398 397 } 399 398 400 399 /**