Skip to contentSkip to conversation

btrfs: fix Wmaybe-uninitialized warning

PATCH In review Austin Kim 2 participants 4 messages Sep 3, 2019 – Oct 7, 2019 Btrfs file system

lore
Share & tools
lore

Austin Kim

author
#0 lore raw

PATCH 1/1 btrfs: fix Wmaybe-uninitialized warning

gcc throws warning message as below:

‘clone_src_i_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]

 #define IS_ALIGNED(x, a)  (((x) & ((typeof(x))(a) - 1)) == 0)
                       ^

fs/btrfs/send.c:5088:6: note: ‘clone_src_i_size’ was declared here
u64 clone_src_i_size;
^
The clone_src_i_size is only used as call-by-reference in a call to get_inode_info().

Silence the warning by initializing clone_src_i_size to 0.

---
 fs/btrfs/send.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/send.c +1 -1
index f856d6c..197536b 100644
@@ -5085,7 +5085,7 @@ static int clone_range(struct send_ctx *sctx,
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	int ret;
-	u64 clone_src_i_size;
+	u64 clone_src_i_size = 0;
 
 	/*
 	 * Prevent cloning from a zero offset with a length matching the sector
Signature · 1 line
2.6.2
author
#1 lore raw

Hello, maintainers.

If you are available, please review this patch and share the feedback.

Thanks,
Austin Kim

2019년 9월 3일 (화) 오후 12:30, Austin Kim <[email protected]>님이 작성:

Quoted 36 lines

gcc throws warning message as below:

‘clone_src_i_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]

 #define IS_ALIGNED(x, a)  (((x) & ((typeof(x))(a) - 1)) == 0)
                       ^
fs/btrfs/send.c:5088:6: note: ‘clone_src_i_size’ was declared here
 u64 clone_src_i_size;
   ^

The clone_src_i_size is only used as call-by-reference in a call to get_inode_info().

Silence the warning by initializing clone_src_i_size to 0.

---
 fs/btrfs/send.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/send.c +1 -2
index f856d6c..197536b 100644
@@ -5085,7 +5085,7 @@ static int clone_range(struct send_ctx *sctx,
        struct btrfs_path *path;
        struct btrfs_key key;
        int ret;
-       u64 clone_src_i_size;
+       u64 clone_src_i_size = 0;
 
        /*
         * Prevent cloning from a zero offset with a length matching the sector
--

2.6.2

#2 lore raw
In reply to Austin Kim
Quoted 1 line · Austin Kim

gcc throws warning message as below:

What version of gcc reports that? 9.2.1 does not.

Quoted 9 lines

‘clone_src_i_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]

 #define IS_ALIGNED(x, a)  (((x) & ((typeof(x))(a) - 1)) == 0)
                       ^
fs/btrfs/send.c:5088:6: note: ‘clone_src_i_size’ was declared here
 u64 clone_src_i_size;
   ^

The clone_src_i_size is only used as call-by-reference in a call to get_inode_info().

The reference is passed to a static function, so the compiler has enough information to determine if it's unused. By inspection I don't see a problem with the uninitalized variable: if __get_inode_info succeeds, there's a valid value, in error case it's not used at all.

#3 lore raw
In reply to Austin Kim
Quoted 9 lines · Austin Kim

gcc throws warning message as below:

‘clone_src_i_size’ may be used uninitialized in this function [-Wmaybe-uninitialized]

 #define IS_ALIGNED(x, a)  (((x) & ((typeof(x))(a) - 1)) == 0)
                       ^
fs/btrfs/send.c:5088:6: note: ‘clone_src_i_size’ was declared here
 u64 clone_src_i_size;
   ^
Quoted 6 lines

The clone_src_i_size is only used as call-by-reference in a call to get_inode_info().

Silence the warning by initializing clone_src_i_size to 0.

A few more people have repoted this warning, so I'm gonig to apply the patch to avoid further reports. Thanks.