[PATCH] btrfs: fix uninitialized variable warnings

pengfuyuan posted 1 patch 2 years, 8 months ago
fs/btrfs/tree-log.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] btrfs: fix uninitialized variable warnings
Posted by pengfuyuan 2 years, 8 months ago

There are some warnings on older compilers (gcc 10, 7) or non-x86_64
architectures (mips64).  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/tree-log.c: In function \ufffd\ufffd\ufffdbtrfs_log_inode\ufffd\ufffd\ufffd:
    fs/btrfs/tree-log.c:6211:9: error: \ufffd\ufffd\ufffdlast_range_start\ufffd\ufffd\ufffd may be used uninitialized in this function [-Werror=maybe-uninitialized]
     6211 |   ret = insert_dir_log_key(trans, log, path, key.objectid,
          |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     6212 |       first_dir_index, last_dir_index);
          |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/btrfs/tree-log.c:6161:6: note: \ufffd\ufffd\ufffdlast_range_start\ufffd\ufffd\ufffd was declared here
     6161 |  u64 last_range_start;
          |      ^~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors

Reported-by: k2ci <kernel-bot@kylinos.cn>
Signed-off-by: pengfuyuan <pengfuyuan@kylinos.cn>
---
 fs/btrfs/tree-log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 9b212e8c70cc..d2755d5e338b 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -6158,7 +6158,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;
 
-- 
2.25.1

Content-type: Text/plain

No virus found
		Checked by Hillstone Network AntiVirus
Re: [PATCH] btrfs: fix uninitialized variable warnings
Posted by David Sterba 2 years, 8 months ago
On Tue, May 23, 2023 at 04:59:35PM +0800, pengfuyuan wrote:
> 
> There are some warnings on older compilers (gcc 10, 7) or non-x86_64
> architectures (mips64).  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/tree-log.c: In function ???btrfs_log_inode???:
>     fs/btrfs/tree-log.c:6211:9: error: ???last_range_start??? may be used uninitialized in this function [-Werror=maybe-uninitialized]
>      6211 |   ret = insert_dir_log_key(trans, log, path, key.objectid,
>           |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>      6212 |       first_dir_index, last_dir_index);
>           |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     fs/btrfs/tree-log.c:6161:6: note: ???last_range_start??? was declared here
>      6161 |  u64 last_range_start;
>           |      ^~~~~~~~~~~~~~~~
>     cc1: all warnings being treated as errors
> 
> Reported-by: k2ci <kernel-bot@kylinos.cn>
> Signed-off-by: pengfuyuan <pengfuyuan@kylinos.cn>

Thanks, this warning got reported reported recently [1] and the fix is
now in queue.

[1] https://lore.kernel.org/linux-btrfs/20230516013430.2712449-1-zhangshida@kylinos.cn/