diff mbox series

[v2,21/42] btrfs: have proper error handling in btrfs_init_reloc_root

Message ID 95d76970dcca9b6f1d523339b8ec62429813a0fd.1605284383.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series [v2,01/42] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block | expand

Commit Message

Josef Bacik Nov. 13, 2020, 4:23 p.m. UTC
create_reloc_root will return errors in the future, and __add_reloc_root
can return -ENOMEM or -EEXIST, so handle these errors properly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 63f42aa43fa3..4afba27419f0 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -860,9 +860,14 @@  int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
 	reloc_root = create_reloc_root(trans, root, root->root_key.objectid);
 	if (clear_rsv)
 		trans->block_rsv = rsv;
+	if (IS_ERR(reloc_root))
+		return PTR_ERR(reloc_root);
 
 	ret = __add_reloc_root(reloc_root);
-	BUG_ON(ret < 0);
+	if (ret) {
+		btrfs_put_root(reloc_root);
+		return ret;
+	}
 	root->reloc_root = btrfs_grab_root(reloc_root);
 	return 0;
 }