Commit 1028d1c4 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: remove err variable from btrfs_get_extent

There's no practical reason too use 'err' as a variable to convey
errors. In fact it's value is either set explicitly in the beginning of
the function or it simply takes the value of 'ret'. Not conforming to
the usual pattern of having ret be the only variable used to convey
errors makes the code more error prone to bugs. In fact one such bug
was introduced by 6bf9e4bd ("btrfs: inode: Verify inode mode toi
avoid NULL pointer dereference") by assigning the error value to 'ret'
and not 'err'.

Let's fix that issue and make the function less tricky by leaving only
ret to convey error values.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 0eb79294
......@@ -6534,8 +6534,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
u64 start, u64 len)
{
struct btrfs_fs_info *fs_info = inode->root->fs_info;
int ret;
int err = 0;
int ret = 0;
u64 extent_start = 0;
u64 extent_end = 0;
u64 objectid = btrfs_ino(inode);
......@@ -6563,7 +6562,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
}
em = alloc_extent_map();
if (!em) {
err = -ENOMEM;
ret = -ENOMEM;
goto out;
}
em->start = EXTENT_MAP_HOLE;
......@@ -6573,7 +6572,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
path = btrfs_alloc_path();
if (!path) {
err = -ENOMEM;
ret = -ENOMEM;
goto out;
}
......@@ -6588,12 +6587,12 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
ret = btrfs_lookup_file_extent(NULL, root, path, objectid, start, 0);
if (ret < 0) {
err = ret;
goto out;
} else if (ret > 0) {
if (path->slots[0] == 0)
goto not_found;
path->slots[0]--;
ret = 0;
}
leaf = path->nodes[0];
......@@ -6619,7 +6618,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
/* Only regular file could have regular/prealloc extent */
if (!S_ISREG(inode->vfs_inode.i_mode)) {
err = -EUCLEAN;
ret = -EUCLEAN;
btrfs_crit(fs_info,
"regular/prealloc extent found for non-regular inode %llu",
btrfs_ino(inode));
......@@ -6637,12 +6636,11 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
path->slots[0]++;
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
ret = btrfs_next_leaf(root, path);
if (ret < 0) {
err = ret;
if (ret < 0)
goto out;
} else if (ret > 0) {
else if (ret > 0)
goto not_found;
}
leaf = path->nodes[0];
}
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
......@@ -6693,10 +6691,8 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
BTRFS_COMPRESS_NONE) {
ret = uncompress_inline(path, page, pg_offset,
extent_offset, item);
if (ret) {
err = ret;
if (ret)
goto out;
}
} else {
map = kmap(page);
read_extent_buffer(leaf, map + pg_offset, ptr,
......@@ -6720,27 +6716,27 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
em->len = len;
em->block_start = EXTENT_MAP_HOLE;
insert:
ret = 0;
btrfs_release_path(path);
if (em->start > start || extent_map_end(em) <= start) {
btrfs_err(fs_info,
"bad extent! em: [%llu %llu] passed [%llu %llu]",
em->start, em->len, start, len);
err = -EIO;
ret = -EIO;
goto out;
}
err = 0;
write_lock(&em_tree->lock);
err = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
write_unlock(&em_tree->lock);
out:
btrfs_free_path(path);
trace_btrfs_get_extent(root, inode, em);
if (err) {
if (ret) {
free_extent_map(em);
return ERR_PTR(err);
return ERR_PTR(ret);
}
return em;
}
......
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