btrfs: fix uninitialized variable warnings
authorGenjian Zhang <zhanggenjian@kylinos.cn>
Fri, 24 Mar 2023 02:08:38 +0000 (10:08 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 17 Apr 2023 17:52:19 +0000 (19:52 +0200)
There are some warnings on older compilers (gcc 10, 7) or non-x86_64
architectures (aarch64).  As btrfs wants to enable -Wmaybe-uninitialized
by default, fix the warnings even though it's not necessary on recent
compilers (gcc 12+).

../fs/btrfs/volumes.c: In function ‘btrfs_init_new_device’:
../fs/btrfs/volumes.c:2703:3: error: ‘seed_devices’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 2703 |   btrfs_setup_sprout(fs_info, seed_devices);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../fs/btrfs/send.c: In function ‘get_cur_inode_state’:
../include/linux/compiler.h:70:32: error: ‘right_gen’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   70 |   (__if_trace.miss_hit[1]++,1) :  \
      |                                ^
../fs/btrfs/send.c:1878:6: note: ‘right_gen’ was declared here
 1878 |  u64 right_gen;
      |      ^~~~~~~~~

Reported-by: k2ci <kernel-bot@kylinos.cn>
Signed-off-by: Genjian Zhang <zhanggenjian@kylinos.cn>
Reviewed-by: David Sterba <dsterba@suse.com>
[ update changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c
fs/btrfs/volumes.c

index e5c963bb873db7f56ab0431ac7ce8fd0b450ca11..af2e153543a5c2bce1b3fed19392f789d71626d4 100644 (file)
@@ -1875,7 +1875,7 @@ static int get_cur_inode_state(struct send_ctx *sctx, u64 ino, u64 gen,
        int left_ret;
        int right_ret;
        u64 left_gen;
-       u64 right_gen;
+       u64 right_gen = 0;
        struct btrfs_inode_info info;
 
        ret = get_inode_info(sctx->send_root, ino, &info);
index db6e15205be56de40a462a40ad370beaaacb4753..03f52e4a20aa9b695c7bb498e1e4a9e16b25488b 100644 (file)
@@ -2617,7 +2617,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
        struct block_device *bdev;
        struct super_block *sb = fs_info->sb;
        struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
-       struct btrfs_fs_devices *seed_devices;
+       struct btrfs_fs_devices *seed_devices = NULL;
        u64 orig_super_total_bytes;
        u64 orig_super_num_devices;
        int ret = 0;