[PATCH] xfs: fix inverted action for empty leaf block in xfs_dir2_leafn_toosmall

From: jianyungao89

Date: Tue Nov 03 2026 - 09:42:58 EST


From: Jianyun Gao <jianyungao89@xxxxxxxxx>

When a directory/attribute leaf block becomes empty,
xfs_dir2_leafn_toosmall decides whether to delete it by calling
xfs_da3_path_shift to find a sibling. rval is non-zero when no sibling
is found and zero when one is found.

The code currently sets *action = rval ? 2 : 0, which is backwards: it
tries to delete the block when no sibling exists (corrupting the tree
by self-merging) and keeps the empty block when a sibling is found.

The analogous xfs_da3_node_toosmall (xfs_da_btree.c) uses the correct
*action = retval ? 0 : 2, and the non-empty branch in the same function
uses *action = rval ? 0 : 1. Flip the empty-block case to match.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Jianyun Gao <jianyungao89@xxxxxxxxx>
---
fs/xfs/libxfs/xfs_dir2_node.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
index 19cb536e53ef..55244d153f84 100644
--- a/fs/xfs/libxfs/xfs_dir2_node.c
+++ b/fs/xfs/libxfs/xfs_dir2_node.c
@@ -1546,7 +1546,7 @@ xfs_dir2_leafn_toosmall(
&rval);
if (error)
return error;
- *action = rval ? 2 : 0;
+ *action = rval ? 0 : 2;
return 0;
}
/*
--
2.34.1