Btrfs: fix compile error about uninitialized variable
PATCH 1/1 Btrfs: fix compile error about uninitialized variable
From: Minghao Chi <[email protected]>
fs/btrfs/tree-log.c:6166:6: note: 'last_range_start' was declared here fs/btrfs/volumes.c:2598:27: note: 'seed_devices' was declared herefs/btrfs/send.c:1909:13: error: 'right_gen' may be used uninitialized in this function [-Werror=maybe-uninitialized]
--- fs/btrfs/send.c | 2 +- fs/btrfs/tree-log.c | 2 +- fs/btrfs/volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/send.c +1 -1
@@ -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);
fs/btrfs/tree-log.c +1 -1
@@ -6163,7 +6163,7 @@ static int log_delayed_deletions_incremental(struct btrfs_trans_handle *trans, {struct btrfs_root *log = inode->root->log_root;const struct btrfs_delayed_item *curr; -u64 last_range_start; +u64 last_range_start =0 ;u64 last_range_end =0 ;struct btrfs_key key;
fs/btrfs/volumes.c +1 -1
@@ -2595,7 +2595,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathstruct 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 ;
Signature · 1 line
2.25.1
Quoted 5 lines · On 2023/2/1 10:22, [email protected] wrote:
From: Minghao Chi <[email protected]>
fs/btrfs/tree-log.c:6166:6: note: 'last_range_start' was declared herefs/btrfs/volumes.c:2598:27: note: 'seed_devices' was declared herefs/btrfs/send.c:1909:13: error: 'right_gen' may be used uninitialized in this function [-Werror=maybe-uninitialized]
Have you really dig into the code?
When @right_gen is not initialized, we have @right_ret assigned to -ENOENT.
Thus all later code checking @right_gen would not be executed, and this is a false alert.
You should explain this is a false alert first.
Secondly it's easy to just stick a "= 0" to whatever compiler complains in this case, but since it's a false alert, you really need to explain your compiler version to see if it's really better to fix in the code other than your compiler.
Quoted 48 lines
Signed-off-by Minghao Chi <[email protected]>Signed-off-by ye xingchen <[email protected]>--- fs/btrfs/send.c | 2 +- fs/btrfs/tree-log.c | 2 +- fs/btrfs/volumes.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)fs/btrfs/send.c +1
-1@@ -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);fs/btrfs/tree-log.c +1
-1@@ -6163,7 +6163,7 @@ static int log_delayed_deletions_incremental(struct btrfs_trans_handle *trans, {struct btrfs_root *log = inode->root->log_root;const struct btrfs_delayed_item *curr; -u64 last_range_start; +u64 last_range_start =0 ;u64 last_range_end =0 ;struct btrfs_key key;fs/btrfs/volumes.c +1
-1@@ -2595,7 +2595,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_pathstruct 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 ;
Quoted 5 lines · On Wed, Feb 01, 2023 at 10:22:19AM +0800, [email protected] wrote:
From: Minghao Chi <[email protected]>
fs/btrfs/tree-log.c:6166:6: note: 'last_range_start' was declared herefs/btrfs/volumes.c:2598:27: note: 'seed_devices' was declared herefs/btrfs/send.c:1909:13: error: 'right_gen' may be used uninitialized in this function [-Werror=maybe-uninitialized]
We have the warning -Wmaybe-uninitialized enabled locally for fs/btrfs/ and no pending compiler warnings but in case you find something please tell us which compiler and version it is. Sometimes it makes sense to fix warnings for older yet still widely used versions.