Skip to content

Commit db5b493

Browse files
Tsutomu Itohroot
authored andcommitted
Btrfs: cleanup some BUG_ON()
This patch changes some BUG_ON() to the error return. (but, most callers still use BUG_ON()) Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 1abe9b8 commit db5b493

9 files changed

Lines changed: 54 additions & 23 deletions

File tree

‎fs/btrfs/ctree.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,8 @@ int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
37093709
unsigned long ptr;
37103710

37113711
path = btrfs_alloc_path();
3712-
BUG_ON(!path);
3712+
if (!path)
3713+
return -ENOMEM;
37133714
ret = btrfs_insert_empty_item(trans, root, path, cpu_key, data_size);
37143715
if (!ret) {
37153716
leaf = path->nodes[0];

‎fs/btrfs/disk-io.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,10 @@ struct btrfs_root *btrfs_read_fs_root_no_radix(struct btrfs_root *tree_root,
12481248
root, fs_info, location->objectid);
12491249

12501250
path = btrfs_alloc_path();
1251-
BUG_ON(!path);
1251+
if (!path) {
1252+
kfree(root);
1253+
return ERR_PTR(-ENOMEM);
1254+
}
12521255
ret = btrfs_search_slot(NULL, tree_root, location, path, 0, 0);
12531256
if (ret == 0) {
12541257
l = path->nodes[0];

‎fs/btrfs/extent-tree.c‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,7 +5463,8 @@ static int alloc_reserved_file_extent(struct btrfs_trans_handle *trans,
54635463
size = sizeof(*extent_item) + btrfs_extent_inline_ref_size(type);
54645464

54655465
path = btrfs_alloc_path();
5466-
BUG_ON(!path);
5466+
if (!path)
5467+
return -ENOMEM;
54675468

54685469
path->leave_spinning = 1;
54695470
ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path,
@@ -6457,10 +6458,14 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
64576458
BUG_ON(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
64586459

64596460
path = btrfs_alloc_path();
6460-
BUG_ON(!path);
6461+
if (!path)
6462+
return -ENOMEM;
64616463

64626464
wc = kzalloc(sizeof(*wc), GFP_NOFS);
6463-
BUG_ON(!wc);
6465+
if (!wc) {
6466+
btrfs_free_path(path);
6467+
return -ENOMEM;
6468+
}
64646469

64656470
btrfs_assert_tree_locked(parent);
64666471
parent_level = btrfs_header_level(parent);
@@ -6918,7 +6923,11 @@ static noinline int get_new_locations(struct inode *reloc_inode,
69186923
}
69196924

69206925
path = btrfs_alloc_path();
6921-
BUG_ON(!path);
6926+
if (!path) {
6927+
if (exts != *extents)
6928+
kfree(exts);
6929+
return -ENOMEM;
6930+
}
69226931

69236932
cur_pos = extent_key->objectid - offset;
69246933
last_byte = extent_key->objectid + extent_key->offset;
@@ -7442,7 +7451,8 @@ static noinline int replace_extents_in_leaf(struct btrfs_trans_handle *trans,
74427451
int ret;
74437452

74447453
new_extent = kmalloc(sizeof(*new_extent), GFP_NOFS);
7445-
BUG_ON(!new_extent);
7454+
if (!new_extent)
7455+
return -ENOMEM;
74467456

74477457
ref = btrfs_lookup_leaf_ref(root, leaf->start);
74487458
BUG_ON(!ref);
@@ -7647,7 +7657,8 @@ static noinline int init_reloc_tree(struct btrfs_trans_handle *trans,
76477657
return 0;
76487658

76497659
root_item = kmalloc(sizeof(*root_item), GFP_NOFS);
7650-
BUG_ON(!root_item);
7660+
if (!root_item)
7661+
return -ENOMEM;
76517662

76527663
ret = btrfs_copy_root(trans, root, root->commit_root,
76537664
&eb, BTRFS_TREE_RELOC_OBJECTID);
@@ -7673,7 +7684,7 @@ static noinline int init_reloc_tree(struct btrfs_trans_handle *trans,
76737684

76747685
reloc_root = btrfs_read_fs_root_no_radix(root->fs_info->tree_root,
76757686
&root_key);
7676-
BUG_ON(!reloc_root);
7687+
BUG_ON(IS_ERR(reloc_root));
76777688
reloc_root->last_trans = trans->transid;
76787689
reloc_root->commit_root = NULL;
76797690
reloc_root->ref_tree = &root->fs_info->reloc_ref_tree;

‎fs/btrfs/file-item.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
4848
struct extent_buffer *leaf;
4949

5050
path = btrfs_alloc_path();
51-
BUG_ON(!path);
51+
if (!path)
52+
return -ENOMEM;
5253
file_key.objectid = objectid;
5354
file_key.offset = pos;
5455
btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);

‎fs/btrfs/inode-map.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int btrfs_find_highest_inode(struct btrfs_root *root, u64 *objectid)
3030
int slot;
3131

3232
path = btrfs_alloc_path();
33-
BUG_ON(!path);
33+
if (!path)
34+
return -ENOMEM;
3435

3536
search_key.objectid = BTRFS_LAST_FREE_OBJECTID;
3637
search_key.type = -1;

‎fs/btrfs/ioctl.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,12 +2350,15 @@ static noinline long btrfs_ioctl_start_sync(struct file *file, void __user *argp
23502350
struct btrfs_root *root = BTRFS_I(file->f_dentry->d_inode)->root;
23512351
struct btrfs_trans_handle *trans;
23522352
u64 transid;
2353+
int ret;
23532354

23542355
trans = btrfs_start_transaction(root, 0);
23552356
if (IS_ERR(trans))
23562357
return PTR_ERR(trans);
23572358
transid = trans->transid;
2358-
btrfs_commit_transaction_async(trans, root, 0);
2359+
ret = btrfs_commit_transaction_async(trans, root, 0);
2360+
if (ret)
2361+
return ret;
23592362

23602363
if (argp)
23612364
if (copy_to_user(argp, &transid, sizeof(transid)))

‎fs/btrfs/root-tree.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
8888
search_key.offset = (u64)-1;
8989

9090
path = btrfs_alloc_path();
91-
BUG_ON(!path);
91+
if (!path)
92+
return -ENOMEM;
9293
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
9394
if (ret < 0)
9495
goto out;
@@ -332,7 +333,8 @@ int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
332333
struct extent_buffer *leaf;
333334

334335
path = btrfs_alloc_path();
335-
BUG_ON(!path);
336+
if (!path)
337+
return -ENOMEM;
336338
ret = btrfs_search_slot(trans, root, key, path, -1, 1);
337339
if (ret < 0)
338340
goto out;

‎fs/btrfs/transaction.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ static noinline int join_transaction(struct btrfs_root *root)
5757
if (!cur_trans) {
5858
cur_trans = kmem_cache_alloc(btrfs_transaction_cachep,
5959
GFP_NOFS);
60-
BUG_ON(!cur_trans);
60+
if (!cur_trans)
61+
return -ENOMEM;
6162
root->fs_info->generation++;
6263
cur_trans->num_writers = 1;
6364
cur_trans->num_joined = 0;
@@ -195,7 +196,11 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
195196
wait_current_trans(root);
196197

197198
ret = join_transaction(root);
198-
BUG_ON(ret);
199+
if (ret < 0) {
200+
if (type != TRANS_JOIN_NOLOCK)
201+
mutex_unlock(&root->fs_info->trans_mutex);
202+
return ERR_PTR(ret);
203+
}
199204

200205
cur_trans = root->fs_info->running_transaction;
201206
cur_trans->use_count++;
@@ -1156,7 +1161,8 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans,
11561161
struct btrfs_transaction *cur_trans;
11571162

11581163
ac = kmalloc(sizeof(*ac), GFP_NOFS);
1159-
BUG_ON(!ac);
1164+
if (!ac)
1165+
return -ENOMEM;
11601166

11611167
INIT_DELAYED_WORK(&ac->work, do_async_commit);
11621168
ac->root = root;

‎fs/btrfs/tree-log.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,8 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
18281828
int orig_level;
18291829

18301830
path = btrfs_alloc_path();
1831-
BUG_ON(!path);
1831+
if (!path)
1832+
return -ENOMEM;
18321833

18331834
level = btrfs_header_level(log->node);
18341835
orig_level = level;
@@ -3114,17 +3115,20 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
31143115
.stage = 0,
31153116
};
31163117

3117-
fs_info->log_root_recovering = 1;
31183118
path = btrfs_alloc_path();
3119-
BUG_ON(!path);
3119+
if (!path)
3120+
return -ENOMEM;
3121+
3122+
fs_info->log_root_recovering = 1;
31203123

31213124
trans = btrfs_start_transaction(fs_info->tree_root, 0);
31223125
BUG_ON(IS_ERR(trans));
31233126

31243127
wc.trans = trans;
31253128
wc.pin = 1;
31263129

3127-
walk_log_tree(trans, log_root_tree, &wc);
3130+
ret = walk_log_tree(trans, log_root_tree, &wc);
3131+
BUG_ON(ret);
31283132

31293133
again:
31303134
key.objectid = BTRFS_TREE_LOG_OBJECTID;
@@ -3148,8 +3152,7 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
31483152

31493153
log = btrfs_read_fs_root_no_radix(log_root_tree,
31503154
&found_key);
3151-
BUG_ON(!log);
3152-
3155+
BUG_ON(IS_ERR(log));
31533156

31543157
tmp_key.objectid = found_key.offset;
31553158
tmp_key.type = BTRFS_ROOT_ITEM_KEY;

0 commit comments

Comments
 (0)