btrfs-progs: handle errors from btrfs_alloc_path
authorDavid Sterba <dsterba@suse.com>
Wed, 31 Aug 2016 18:38:46 +0000 (20:38 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Sep 2016 12:12:38 +0000 (14:12 +0200)
All functions already return an error condition, so the callers should
expect that.

Signed-off-by: David Sterba <dsterba@suse.com>
ctree.c
disk-io.c
extent-tree.c
file-item.c
inode-map.c
root-tree.c
volumes.c

diff --git a/ctree.c b/ctree.c
index a98ad18..d07ec7d 100644 (file)
--- 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];
index 2fd3330..b7202fa 100644 (file)
--- 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)
index 0607be6..fb62794 100644 (file)
@@ -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);
index 7a3bbf3..55d2d47 100644 (file)
@@ -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;
index 9e4dcd3..9000e69 100644 (file)
@@ -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);
index 934d02e..cca424e 100644 (file)
@@ -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;
index 2d07e66..e022c16 100644 (file)
--- 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;