fs: don't assume arguments are non-NULL

The helper is explicitly documented as locking zero, one, or two
arguments. While all current callers do pass non-NULL arguments there's
no need or requirement for them to do so according to the code and the
unlock_two_nondirectories() helper is pretty clear about it as well. So
only call WARN_ON_ONCE() if the checked inode is valid.

Fixes: 2454ad83b9 ("fs: Restrict lock_two_nondirectories() to non-directory inodes")
Reviewed-by: Jan Kara <jack@suse.cz>
Cc: Jan Kara <jack@suse.cz>
Message-Id: <20230703-vfs-rename-source-v1-2-37eebb29b65b@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Christian Brauner 2023-07-03 16:49:12 +02:00
parent 66d8fc0539
commit 33ab231f83
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2

View File

@ -1156,8 +1156,10 @@ lock:
*/ */
void lock_two_nondirectories(struct inode *inode1, struct inode *inode2) void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
{ {
WARN_ON_ONCE(S_ISDIR(inode1->i_mode)); if (inode1)
WARN_ON_ONCE(S_ISDIR(inode2->i_mode)); WARN_ON_ONCE(S_ISDIR(inode1->i_mode));
if (inode2)
WARN_ON_ONCE(S_ISDIR(inode2->i_mode));
lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2); lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2);
} }
EXPORT_SYMBOL(lock_two_nondirectories); EXPORT_SYMBOL(lock_two_nondirectories);