[PATCH] exfat: fix parent link count when replacing a sibling directory

From: Hungyu Lin

Date: Wed Oct 28 2026 - 16:33:59 EST


exfat_rename() adjusts parent link counts only when a directory moves
between different parents. Replacing an existing empty directory in the
same parent also removes one subdirectory, but leaves the parent's
link count unchanged. For example, renaming one of two sibling
directories over the other leaves the parent with four links instead
of three.

Also adjust the parent count when a target inode exists in the directory
rename case. Keep same-parent renames without replacement and the
existing cross-parent accounting unchanged.

Fixes: 5f2aa075070c ("exfat: add inode operations")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/exfat/namei.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 68ddb9c5504f..24110e7fde47 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -1309,7 +1309,7 @@ static int exfat_rename(const struct mnt_idmap *idmap,
else
mark_inode_dirty(old_inode);

- if (S_ISDIR(old_inode->i_mode) && old_dir != new_dir) {
+ if (S_ISDIR(old_inode->i_mode) && (old_dir != new_dir || new_inode)) {
drop_nlink(old_dir);
if (!new_inode)
inc_nlink(new_dir);
--
2.43.0