]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
btrfs: zoned: fix uninitialized variable warning in btrfs_get_dev_zones
authorNaohiro Aota <Naohiro.Aota@wdc.com>
Wed, 21 Dec 2022 16:47:45 +0000 (16:47 +0000)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Feb 2023 16:50:33 +0000 (17:50 +0100)
Fix an uninitialized warning we get with -Wmaybe-uninitialized where it
thought zno may have been uninitialized, in both cases it depends on
zinfo->zone_cache but we know the value won't change between checks.

Reported-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/linux-btrfs/af6c527cbd8bdc782e50bd33996ee83acc3a16fb.1671221596.git.josef@toxicpanda.com/
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zoned.c

index 379d678e3894ed324ebc0e8c8117fba4dc653779..d46701a77b1728f4010702d887dbf7fc5d0a3632 100644 (file)
@@ -220,7 +220,6 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
                               struct blk_zone *zones, unsigned int *nr_zones)
 {
        struct btrfs_zoned_device_info *zinfo = device->zone_info;
-       u32 zno;
        int ret;
 
        if (!*nr_zones)
@@ -235,6 +234,7 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
        /* Check cache */
        if (zinfo->zone_cache) {
                unsigned int i;
+               u32 zno;
 
                ASSERT(IS_ALIGNED(pos, zinfo->zone_size));
                zno = pos >> zinfo->zone_size_shift;
@@ -274,9 +274,12 @@ static int btrfs_get_dev_zones(struct btrfs_device *device, u64 pos,
                return -EIO;
 
        /* Populate cache */
-       if (zinfo->zone_cache)
+       if (zinfo->zone_cache) {
+               u32 zno = pos >> zinfo->zone_size_shift;
+
                memcpy(zinfo->zone_cache + zno, zones,
                       sizeof(*zinfo->zone_cache) * *nr_zones);
+       }
 
        return 0;
 }