From 1ef93ea8632b89598d7723a04a2d268b70333168 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 31 Aug 2016 20:38:46 +0200 Subject: [PATCH] btrfs-progs: handle errors from btrfs_alloc_path All functions already return an error condition, so the callers should expect that. Signed-off-by: David Sterba --- ctree.c | 4 +++- disk-io.c | 6 +++++- extent-tree.c | 3 ++- file-item.c | 7 +++++-- inode-map.c | 4 +++- root-tree.c | 10 +++++++--- volumes.c | 3 ++- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ctree.c b/ctree.c index a98ad18..d07ec7d 100644 --- a/ctree.c +++ b/ctree.c @@ -2580,7 +2580,9 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root unsigned long ptr; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + ret = btrfs_insert_empty_item(trans, root, path, cpu_key, data_size); if (!ret) { leaf = path->nodes[0]; diff --git a/disk-io.c b/disk-io.c index 2fd3330..b7202fa 100644 --- a/disk-io.c +++ b/disk-io.c @@ -739,7 +739,11 @@ struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info, root, fs_info, location->objectid); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) { + free(root); + return ERR_PTR(-ENOMEM); + } + ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0); if (ret != 0) { if (ret > 0) diff --git a/extent-tree.c b/extent-tree.c index 0607be6..fb62794 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -2714,7 +2714,8 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, size += sizeof(*block_info); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, ins, size); diff --git a/file-item.c b/file-item.c index 7a3bbf3..55d2d47 100644 --- a/file-item.c +++ b/file-item.c @@ -42,7 +42,9 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, struct extent_buffer *leaf; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + file_key.objectid = objectid; file_key.offset = pos; btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY); @@ -188,7 +190,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, btrfs_super_csum_size(root->fs_info->super_copy); path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; file_key.objectid = BTRFS_EXTENT_CSUM_OBJECTID; file_key.offset = bytenr; diff --git a/inode-map.c b/inode-map.c index 9e4dcd3..9000e69 100644 --- a/inode-map.c +++ b/inode-map.c @@ -39,7 +39,9 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, u64 search_start = dirid; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + search_start = root->last_inode_alloc; search_start = max((unsigned long long)search_start, BTRFS_FIRST_FREE_OBJECTID); diff --git a/root-tree.c b/root-tree.c index 934d02e..cca424e 100644 --- a/root-tree.c +++ b/root-tree.c @@ -31,12 +31,14 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, int ret; int slot; + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + search_key.objectid = objectid; search_key.type = BTRFS_ROOT_ITEM_KEY; search_key.offset = (u64)-1; - path = btrfs_alloc_path(); - BUG_ON(!path); ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); if (ret < 0) goto out; @@ -74,7 +76,9 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root u32 old_len; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + ret = btrfs_search_slot(trans, root, key, path, 0, 1); if (ret < 0) goto out; diff --git a/volumes.c b/volumes.c index 2d07e66..e022c16 100644 --- a/volumes.c +++ b/volumes.c @@ -459,7 +459,8 @@ static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset) struct btrfs_key found_key; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; key.objectid = objectid; key.offset = (u64)-1; -- 2.7.4