提交 9986277e 编写于 作者: D Dan Carpenter 提交者: David Sterba

Btrfs: handle only applicable errors returned by btrfs_get_extent

btrfs_get_extent() never returns NULL pointers, so this code introduces
a static checker warning.

The btrfs_get_extent() is a bit complex, but trust me that it doesn't
return NULLs and also if it did we would trigger the BUG_ON(!em) before
the last return statement.
Signed-off-by: NDan Carpenter <dan.carpenter@oracle.com>
[ updated subject ]
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 82bafb38
...@@ -2342,13 +2342,8 @@ static int find_first_non_hole(struct inode *inode, u64 *start, u64 *len) ...@@ -2342,13 +2342,8 @@ static int find_first_non_hole(struct inode *inode, u64 *start, u64 *len)
int ret = 0; int ret = 0;
em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, *start, *len, 0); em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, *start, *len, 0);
if (IS_ERR_OR_NULL(em)) { if (IS_ERR(em))
if (!em) return PTR_ERR(em);
ret = -ENOMEM;
else
ret = PTR_ERR(em);
return ret;
}
/* Hole or vacuum extent(only exists in no-hole mode) */ /* Hole or vacuum extent(only exists in no-hole mode) */
if (em->block_start == EXTENT_MAP_HOLE) { if (em->block_start == EXTENT_MAP_HOLE) {
...@@ -2835,11 +2830,8 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -2835,11 +2830,8 @@ static long btrfs_fallocate(struct file *file, int mode,
while (1) { while (1) {
em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset, em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset,
alloc_end - cur_offset, 0); alloc_end - cur_offset, 0);
if (IS_ERR_OR_NULL(em)) { if (IS_ERR(em)) {
if (!em) ret = PTR_ERR(em);
ret = -ENOMEM;
else
ret = PTR_ERR(em);
break; break;
} }
last_byte = min(extent_map_end(em), alloc_end); last_byte = min(extent_map_end(em), alloc_end);
......
...@@ -6736,7 +6736,6 @@ static noinline int uncompress_inline(struct btrfs_path *path, ...@@ -6736,7 +6736,6 @@ static noinline int uncompress_inline(struct btrfs_path *path,
* *
* This also copies inline extents directly into the page. * This also copies inline extents directly into the page.
*/ */
struct extent_map *btrfs_get_extent(struct btrfs_inode *inode, struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
struct page *page, struct page *page,
size_t pg_offset, u64 start, u64 len, size_t pg_offset, u64 start, u64 len,
...@@ -7045,19 +7044,17 @@ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode, ...@@ -7045,19 +7044,17 @@ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
em = btrfs_get_extent(inode, page, pg_offset, start, len, create); em = btrfs_get_extent(inode, page, pg_offset, start, len, create);
if (IS_ERR(em)) if (IS_ERR(em))
return em; return em;
if (em) { /*
/* * If our em maps to:
* if our em maps to * - a hole or
* - a hole or * - a pre-alloc extent,
* - a pre-alloc extent, * there might actually be delalloc bytes behind it.
* there might actually be delalloc bytes behind it. */
*/ if (em->block_start != EXTENT_MAP_HOLE &&
if (em->block_start != EXTENT_MAP_HOLE && !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) return em;
return em; else
else hole_em = em;
hole_em = em;
}
/* check to see if we've wrapped (len == -1 or similar) */ /* check to see if we've wrapped (len == -1 or similar) */
end = start + len; end = start + len;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册