]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: avoid assigning twice to block_start at btrfs_do_readpage()
authorFilipe Manana <fdmanana@suse.com>
Wed, 5 Feb 2025 11:30:34 +0000 (11:30 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:41 +0000 (20:35 +0100)
At btrfs_do_readpage() if we get an extent map for a prealloc extent we
end up assigning twice to the 'block_start' variable, first the value
returned by extent_map_block_start() and then EXTENT_MAP_HOLE. This is
pointless so make it more clear by using an if-else statement and doing
only one assignment. Also, while at it, move the declaration of
'block_start' into the while loop's scope, since it's not used outside of
it and the related 'disk_bytenr' is also declared in this scope.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent_io.c

index 3b557f4fe632f76113e15504ad90830fe951e60d..ffa4110f705671f5158d4fe0ed8e63ccc727fc09 100644 (file)
@@ -939,7 +939,6 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
        u64 cur = start;
        u64 extent_offset;
        u64 last_byte = i_size_read(inode);
-       u64 block_start;
        struct extent_map *em;
        int ret = 0;
        size_t pg_offset = 0;
@@ -966,6 +965,7 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
                enum btrfs_compression_type compress_type = BTRFS_COMPRESS_NONE;
                bool force_bio_submit = false;
                u64 disk_bytenr;
+               u64 block_start;
 
                ASSERT(IS_ALIGNED(cur, fs_info->sectorsize));
                if (cur >= last_byte) {
@@ -991,9 +991,11 @@ static int btrfs_do_readpage(struct folio *folio, struct extent_map **em_cached,
                        disk_bytenr = em->disk_bytenr;
                else
                        disk_bytenr = extent_map_block_start(em) + extent_offset;
-               block_start = extent_map_block_start(em);
+
                if (em->flags & EXTENT_FLAG_PREALLOC)
                        block_start = EXTENT_MAP_HOLE;
+               else
+                       block_start = extent_map_block_start(em);
 
                /*
                 * If we have a file range that points to a compressed extent