Btrfs: handle only applicable errors returned by btrfs_get_extent
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 11 Apr 2017 08:57:15 +0000 (11:57 +0300)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Apr 2017 12:07:27 +0000 (14:07 +0200)
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: Dan Carpenter <dan.carpenter@oracle.com>
[ updated subject ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c
fs/btrfs/inode.c

index 520cb7230b2d2cb5ca798c0030fa446957799456..3cedbfd08a3a325aa11990e301e5a0c2373b54d6 100644 (file)
@@ -2342,13 +2342,8 @@ static int find_first_non_hole(struct inode *inode, u64 *start, u64 *len)
        int ret = 0;
 
        em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, *start, *len, 0);
-       if (IS_ERR_OR_NULL(em)) {
-               if (!em)
-                       ret = -ENOMEM;
-               else
-                       ret = PTR_ERR(em);
-               return ret;
-       }
+       if (IS_ERR(em))
+               return PTR_ERR(em);
 
        /* Hole or vacuum extent(only exists in no-hole mode) */
        if (em->block_start == EXTENT_MAP_HOLE) {
@@ -2835,11 +2830,8 @@ static long btrfs_fallocate(struct file *file, int mode,
        while (1) {
                em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset,
                                      alloc_end - cur_offset, 0);
-               if (IS_ERR_OR_NULL(em)) {
-                       if (!em)
-                               ret = -ENOMEM;
-                       else
-                               ret = PTR_ERR(em);
+               if (IS_ERR(em)) {
+                       ret = PTR_ERR(em);
                        break;
                }
                last_byte = min(extent_map_end(em), alloc_end);
index da71119b5b7c46b13646b7854111a5eb7f5e949b..31759d48e8807b3e18e4eddfb4c1fdf52a91b9ae 100644 (file)
@@ -6736,7 +6736,6 @@ static noinline int uncompress_inline(struct btrfs_path *path,
  *
  * This also copies inline extents directly into the page.
  */
-
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
                struct page *page,
            size_t pg_offset, u64 start, u64 len,
@@ -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);
        if (IS_ERR(em))
                return em;
-       if (em) {
-               /*
-                * if our em maps to
-                * -  a hole or
-                * -  a pre-alloc extent,
-                * there might actually be delalloc bytes behind it.
-                */
-               if (em->block_start != EXTENT_MAP_HOLE &&
-                   !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
-                       return em;
-               else
-                       hole_em = em;
-       }
+       /*
+        * If our em maps to:
+        * - a hole or
+        * - a pre-alloc extent,
+        * there might actually be delalloc bytes behind it.
+        */
+       if (em->block_start != EXTENT_MAP_HOLE &&
+           !test_bit(EXTENT_FLAG_PREALLOC, &em->flags))
+               return em;
+       else
+               hole_em = em;
 
        /* check to see if we've wrapped (len == -1 or similar) */
        end = start + len;