Commit c2db1073 authored by Tsutomu Itoh's avatar Tsutomu Itoh Committed by root

Btrfs: check return value of btrfs_alloc_path()

Adding the check on the return value of btrfs_alloc_path() to several places.
And, some of callers are modified by this change.
Signed-off-by: default avatarTsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent c59021f8
...@@ -663,8 +663,9 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -663,8 +663,9 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
atomic_inc(&cb->pending_bios); atomic_inc(&cb->pending_bios);
if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) { if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
btrfs_lookup_bio_sums(root, inode, comp_bio, ret = btrfs_lookup_bio_sums(root, inode,
sums); comp_bio, sums);
BUG_ON(ret);
} }
sums += (comp_bio->bi_size + root->sectorsize - 1) / sums += (comp_bio->bi_size + root->sectorsize - 1) /
root->sectorsize; root->sectorsize;
...@@ -689,8 +690,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -689,8 +690,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
ret = btrfs_bio_wq_end_io(root->fs_info, comp_bio, 0); ret = btrfs_bio_wq_end_io(root->fs_info, comp_bio, 0);
BUG_ON(ret); BUG_ON(ret);
if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
btrfs_lookup_bio_sums(root, inode, comp_bio, sums); ret = btrfs_lookup_bio_sums(root, inode, comp_bio, sums);
BUG_ON(ret);
}
ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0); ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0);
BUG_ON(ret); BUG_ON(ret);
......
...@@ -151,7 +151,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -151,7 +151,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
ret = PTR_ERR(dir_item); ret = PTR_ERR(dir_item);
if (ret == -EEXIST) if (ret == -EEXIST)
goto second_insert; goto second_insert;
goto out; goto out_free;
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
...@@ -170,7 +170,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -170,7 +170,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
/* FIXME, use some real flag for selecting the extra index */ /* FIXME, use some real flag for selecting the extra index */
if (root == root->fs_info->tree_root) { if (root == root->fs_info->tree_root) {
ret = 0; ret = 0;
goto out; goto out_free;
} }
btrfs_release_path(root, path); btrfs_release_path(root, path);
...@@ -180,7 +180,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -180,7 +180,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
name, name_len); name, name_len);
if (IS_ERR(dir_item)) { if (IS_ERR(dir_item)) {
ret2 = PTR_ERR(dir_item); ret2 = PTR_ERR(dir_item);
goto out; goto out_free;
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
btrfs_cpu_key_to_disk(&disk_key, location); btrfs_cpu_key_to_disk(&disk_key, location);
...@@ -192,7 +192,9 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -192,7 +192,9 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
name_ptr = (unsigned long)(dir_item + 1); name_ptr = (unsigned long)(dir_item + 1);
write_extent_buffer(leaf, name, name_ptr, name_len); write_extent_buffer(leaf, name, name_ptr, name_len);
btrfs_mark_buffer_dirty(leaf); btrfs_mark_buffer_dirty(leaf);
out:
out_free:
btrfs_free_path(path); btrfs_free_path(path);
if (ret) if (ret)
return ret; return ret;
......
...@@ -170,6 +170,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -170,6 +170,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
if (bio->bi_size > PAGE_CACHE_SIZE * 8) if (bio->bi_size > PAGE_CACHE_SIZE * 8)
path->reada = 2; path->reada = 2;
......
...@@ -1467,8 +1467,11 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, ...@@ -1467,8 +1467,11 @@ static int btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio,
if (bio_flags & EXTENT_BIO_COMPRESSED) { if (bio_flags & EXTENT_BIO_COMPRESSED) {
return btrfs_submit_compressed_read(inode, bio, return btrfs_submit_compressed_read(inode, bio,
mirror_num, bio_flags); mirror_num, bio_flags);
} else if (!skip_sum) } else if (!skip_sum) {
btrfs_lookup_bio_sums(root, inode, bio, NULL); ret = btrfs_lookup_bio_sums(root, inode, bio, NULL);
if (ret)
return ret;
}
goto mapit; goto mapit;
} else if (!skip_sum) { } else if (!skip_sum) {
/* csum items have already been cloned */ /* csum items have already been cloned */
...@@ -1903,10 +1906,10 @@ static int btrfs_io_failed_hook(struct bio *failed_bio, ...@@ -1903,10 +1906,10 @@ static int btrfs_io_failed_hook(struct bio *failed_bio,
else else
rw = READ; rw = READ;
BTRFS_I(inode)->io_tree.ops->submit_bio_hook(inode, rw, bio, ret = BTRFS_I(inode)->io_tree.ops->submit_bio_hook(inode, rw, bio,
failrec->last_mirror, failrec->last_mirror,
failrec->bio_flags, 0); failrec->bio_flags, 0);
return 0; return ret;
} }
/* /*
...@@ -5943,9 +5946,12 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, ...@@ -5943,9 +5946,12 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode,
__btrfs_submit_bio_start_direct_io, __btrfs_submit_bio_start_direct_io,
__btrfs_submit_bio_done); __btrfs_submit_bio_done);
goto err; goto err;
} else if (!skip_sum) } else if (!skip_sum) {
btrfs_lookup_bio_sums_dio(root, inode, bio, ret = btrfs_lookup_bio_sums_dio(root, inode, bio,
file_offset, csums); file_offset, csums);
if (ret)
goto err;
}
ret = btrfs_map_bio(root, rw, bio, 0, 1); ret = btrfs_map_bio(root, rw, bio, 0, 1);
err: err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment