The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] btrfs: free mapping node on duplicate reloc root insert
@ 2026-07-11 15:41 Guanghui Yang
  2026-07-11 22:45 ` Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Guanghui Yang @ 2026-07-11 15:41 UTC (permalink / raw)
  To: Chris Mason, David Sterba; +Cc: linux-btrfs, linux-kernel, Guanghui Yang

__add_reloc_root() allocates a mapping_node before inserting it into
rc->reloc_root_tree.  If rb_simple_insert() finds an existing entry, it
returns the existing rb_node and leaves the newly allocated node unlinked.

The error path then returns -EEXIST without freeing the new node.  Since
the node was never inserted into reloc_root_tree, the later cleanup in
put_reloc_control() cannot find it either.

Free the newly allocated node before returning -EEXIST.

The callers currently assert that -EEXIST should not happen, so this is a
defensive cleanup for an unexpected duplicate insert path.  If the path is
ever reached, the local allocation should still be released.

Signed-off-by: Guanghui Yang <3497809730@qq.com>
---
 fs/btrfs/relocation.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index fb85bc8b345c..7e451e587726 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -588,6 +588,7 @@ static int __add_reloc_root(struct btrfs_root *root, struct reloc_control *rc)
 		btrfs_err(fs_info,
 			    "Duplicate root found for start=%llu while inserting into relocation tree",
 			    node->bytenr);
+		kfree(node);
 		return -EEXIST;
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-12  5:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-11 15:41 [PATCH] btrfs: free mapping node on duplicate reloc root insert Guanghui Yang
2026-07-11 22:45 ` Qu Wenruo
2026-07-12  3:11 ` [PATCH v2] ext4: propagate errors from fast commit range replay Guanghui Yang
2026-07-12  3:19   ` Qu Wenruo
2026-07-12  3:27     ` Guanghui Yang
2026-07-12  3:17 ` [PATCH v2] btrfs: free mapping node on duplicate reloc root insert Guanghui Yang
2026-07-12  5:28   ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox