always check btrfs_alloc_path() failure
PATCH 1/1 always check btrfs_alloc_path() failure
There are some places that don't check at all btrfs_alloc_path() failures, I added BUG_ON's for all of them, as many other codepaths that don't know how to handle the failures seem to do.
In case of not applying this patch, I must notice that there's one real bugfix that should be applied, it's a null pointer dereference on inode.c:
2506: path = btrfs_alloc_path();
2507: path->reada = -1;
2508: BUG_ON(!path);
dir-item.c +1 -0
@@ -146,6 +146,7 @@btrfs_set_key_type (&key,BTRFS_DIR_ITEM_KEY ); key.offset =btrfs_name_hash (name, name_len); path =btrfs_alloc_path (); +BUG_ON (!path); data_size =sizeof (*dir_item) + name_len; dir_item =insert_with_overflow (trans, root, path, &key, data_size, name, name_len);
export.c +1 -0
@@ -146,6 +146,7 @@int ret; path =btrfs_alloc_path (); +BUG_ON (!path); key.objectid = dir->i_ino;btrfs_set_key_type (&key,BTRFS_INODE_REF_KEY );
extent-tree.c +3 -0
@@ -1337,6 +1337,7 @@WARN_ON (num_bytes < root->sectorsize); path =btrfs_alloc_path (); +BUG_ON (!path); path->reada =1 ; key.objectid = bytenr; key.offset = num_bytes;
@@ -1377,6 +1378,7 @@ key.type =BTRFS_EXTENT_ITEM_KEY ; path =btrfs_alloc_path (); +BUG_ON (!path); ret =btrfs_search_slot (NULL , extent_root, &key, path,0 ,0 );if (ret <0 ) goto out;
@@ -2132,6 +2134,7 @@int num_inserts =0 , max_inserts; path =btrfs_alloc_path (); +BUG_ON (!path);INIT_LIST_HEAD (&insert_list);INIT_LIST_HEAD (&update_list);
file-item.c +2 -0
@@ -160,6 +160,7 @@struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree; path =btrfs_alloc_path (); +BUG_ON (!path);if (bio->bi_size >PAGE_CACHE_SIZE *8 ) path->reada =2 ;
@@ -506,6 +507,7 @@ root = root->fs_info->csum_root; path =btrfs_alloc_path (); +BUG_ON (!path);while (1 ) { key.objectid =BTRFS_EXTENT_CSUM_OBJECTID ;
file.c +1 -0
@@ -293,6 +293,7 @@u64 extent_end =0 ; path =btrfs_alloc_path (); +BUG_ON (!path); ret =btrfs_lookup_file_extent (NULL , root, path, inode->i_ino, last_offset,0 );while (1 ) {
inode.c +2 -1
@@ -2504,8 +2504,8 @@if (root->ref_cows)btrfs_drop_extent_cache (inode, new_size & (~mask), (u64)-1 ,0 ); path =btrfs_alloc_path (); - path->reada =-1 ;BUG_ON (!path); + path->reada =-1 ;/* FIXME, add redo link to tree so we don't leak on crash */ key.objectid = inode->i_ino;
@@ -3182,6 +3182,7 @@ filp->f_pos =2 ; } path =btrfs_alloc_path (); +BUG_ON (!path); path->reada =2 ;btrfs_set_key_type (&key, key_type);
ioctl.c +1 -0
@@ -292,6 +292,7 @@u64 test_oid;u64 parent_oid =BTRFS_I (dir->d_inode)->root->root_key.objectid; +BUG_ON (!path); test_oid = snap_src->root_key.objectid; ret = btrfs_find_root_ref(snap_src->fs_info->tree_root,
root-tree.c +2 -0
@@ -286,6 +286,7 @@struct btrfs_path *path; path =btrfs_alloc_path (); +BUG_ON (!path); key.objectid = root_id; key.type = type;
@@ -346,6 +347,7 @@ path =btrfs_alloc_path (); +BUG_ON (!path); key.objectid = root_id; key.type = type;
tree-log.c +6 -0
@@ -708,6 +708,7 @@int match =0 ; path =btrfs_alloc_path (); +BUG_ON (!path); ret =btrfs_search_slot (NULL , log, key, path,0 ,0 );if (ret !=0 ) goto out;
@@ -989,6 +990,7 @@ key.offset = (u64)-1 ; path =btrfs_alloc_path (); +BUG_ON (!path);while (1 ) { ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );
@@ -2109,6 +2111,7 @@ log = root->log_root; path =btrfs_alloc_path (); +BUG_ON (!path); di =btrfs_lookup_dir_item (trans, log, path, dir->i_ino, name, name_len,-1 );if (di && !IS_ERR (di)) {
@@ -2476,6 +2479,7 @@list_add_tail (&sums->list, list); path =btrfs_alloc_path (); +BUG_ON (!path);while (disk_bytenr < end) {if (!item || disk_bytenr < item_start_offset || disk_bytenr >= item_last_offset) {
@@ -2683,7 +2687,9 @@ log = root->log_root; path =btrfs_alloc_path (); +BUG_ON (!path); dst_path =btrfs_alloc_path (); +BUG_ON (!dst_path); min_key.objectid = inode->i_ino; min_key.type =BTRFS_INODE_ITEM_KEY ;