Skip to contentSkip to conversation

fs: rename follow-up fixes

PATCH Applied Christian Brauner 2 participants 6 messages Jul 3, 2023 – Jul 4, 2023 VFS

lore
Share & tools
lore

Christian Brauner

author maintainer
#0 lore raw

cover fs: rename follow-up fixes

Jan,

Two minor fixes for the rename work for this cycle. First one is based on a static analysis report from earlier today. The second one is based on manual review.

Thanks!
Christian

---

---
base-commit: a901a3568fd26ca9c4a82d8bc5ed5b3ed844d451
change-id: 20230703-vfs-rename-source-a6093ca69595

author maintainer
#1 lore raw

PATCH 1/2 fs: no need to check source

The @source inode must be valid. It is even checked via IS_SWAPFILE() above making it pretty clear. So no need to check it when we unlock.

What doesn't need to exist is the @target inode. The lock_two_inodes() helper currently swaps the @inode1 and @inode2 arguments if @inode1 is NULL to have consistent lock class usage. However, we know that at least for vfs_rename() that @inode1 is @source and thus is never NULL as per above. We also know that @source is a different inode than @target as that is checked right at the beginning of vfs_rename(). So we know that @source is valid and locked and that @target is locked. So drop the check whether @source is non-NULL.

---
 fs/namei.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/namei.c +1 -2
index 91171da719c5..e56ff39a79bc 100644
@@ -4874,8 +4874,7 @@ int vfs_rename(struct renamedata *rd)
 			d_exchange(old_dentry, new_dentry);
 	}
 out:
-	if (source)
-		inode_unlock(source);
+	inode_unlock(source);
 	if (target)
 		inode_unlock(target);
 	dput(new_dentry);
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/2 fs: don't assume arguments are non-NULL

In reply to Christian Brauner

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.

Cc Jan Kara <[email protected]>
Fixes 2454ad83b90a ("fs: Restrict lock_two_nondirectories() to non-directory inodes")
---
 fs/inode.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/inode.c +4 -2
index d37fad91c8da..8fefb69e1f84 100644
@@ -1156,8 +1156,10 @@ void lock_two_inodes(struct inode *inode1, struct inode *inode2,
  */
 void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
 {
-	WARN_ON_ONCE(S_ISDIR(inode1->i_mode));
-	WARN_ON_ONCE(S_ISDIR(inode2->i_mode));
+	if (inode1)
+		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);
 }
 EXPORT_SYMBOL(lock_two_nondirectories);
Signature · 1 line
2.34.1
reviewer Reviewed-by on the v1 series
#3 lore raw
In reply to Christian Brauner

Hello Christian!

Quoted 3 lines · Christian Brauner

Two minor fixes for the rename work for this cycle. First one is based on a static analysis report from earlier today. The second one is based on manual review.

Thanks! In fact I've sent you a very same patch as patch 1 just a while ago
[1] and your patch 2 already back in June [2]. But feel free to use your fixups, they look good to me so also feel free to add:

Honza

[1] https://lore.kernel.org/all/[email protected]
[2] https://lore.kernel.org/all/20230606095625.zowqbpfi7hktfbwh@quack3

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author maintainer
#4 lore raw
Quoted 7 lines · Jan Kara

Hello Christian!

Quoted 3 lines · Christian Brauner

Two minor fixes for the rename work for this cycle. First one is based on a static analysis report from earlier today. The second one is based on manual review.

Quoted 5 lines

Thanks! In fact I've sent you a very same patch as patch 1 just a while ago
[1] and your patch 2 already back in June [2]. But feel free to use your fixups, they look good to me so also feel free to add:

I'll take yours and just massage the commit message. :)

author maintainer Applied
#5 lore raw
In reply to Christian Brauner
Quoted 10 lines · Christian Brauner

Jan,

Two minor fixes for the rename work for this cycle. First one is based on a static analysis report from earlier today. The second one is based on manual review.

Thanks!
Christian

[...]

I've used your authorship on this, Jan and used my commit message.

---

Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/2] fs: no need to check source

      https://git.kernel.org/vfs/vfs/c/66d8fc0539b0
[2/2] fs: don't assume arguments are non-NULL
      https://git.kernel.org/vfs/vfs/c/33ab231f83cc