diff mbox

btrfs-progs: image: fix compiler warning

Message ID 201610050807.AA00000@WIN-5MHF4RKU941.jp.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Tsutomu Itoh Oct. 5, 2016, 8:07 a.m. UTC
In v4.8-rc1, gcc 5.3.1 gives following warning. Fixed it.

    [CC]     btrfs-image.o
btrfs-image.c: In function 'flush_pending':
btrfs-image.c:708:17: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
  header->bytenr = cpu_to_le64(start);
                 ^
btrfs-image.c:927:6: note: 'start' was declared here
  u64 start;
      ^

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
---
 btrfs-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Sterba Oct. 6, 2016, 4 p.m. UTC | #1
On Wed, Oct 05, 2016 at 05:07:48PM +0900, Tsutomu Itoh wrote:
> In v4.8-rc1, gcc 5.3.1 gives following warning. Fixed it.
> 
>     [CC]     btrfs-image.o
> btrfs-image.c: In function 'flush_pending':
> btrfs-image.c:708:17: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
>   header->bytenr = cpu_to_le64(start);
>                  ^
> btrfs-image.c:927:6: note: 'start' was declared here
>   u64 start;
>       ^

So the patch makes the compiler warning go away, but is the code
correct? AFAICS, the warning points to the case where flush_pending is
called with done=1 (from create_metadump) and there's zero
md->pending_size . Are you sure this is an expected state and that the
function can proceed with state = 0 ?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tsutomu Itoh Oct. 7, 2016, 2:40 a.m. UTC | #2
On 2016/10/07 1:00, David Sterba wrote:
> On Wed, Oct 05, 2016 at 05:07:48PM +0900, Tsutomu Itoh wrote:
>> In v4.8-rc1, gcc 5.3.1 gives following warning. Fixed it.
>>
>>     [CC]     btrfs-image.o
>> btrfs-image.c: In function 'flush_pending':
>> btrfs-image.c:708:17: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
>>   header->bytenr = cpu_to_le64(start);
>>                  ^
>> btrfs-image.c:927:6: note: 'start' was declared here
>>   u64 start;
>>       ^
> 
> So the patch makes the compiler warning go away, but is the code
> correct? AFAICS, the warning points to the case where flush_pending is
> called with done=1 (from create_metadump) and there's zero
> md->pending_size . Are you sure this is an expected state and that the
> function can proceed with state = 0 ?
> 

I think that this is a case where some errors occurred before calling
flush_pending.
Therefore, create_metadump returns the error to the caller. (creating
the image fails, I think.)

Thanks,
Tsutomu

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/btrfs-image.c b/btrfs-image.c
index 0d410f8..47f36b9 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -924,7 +924,7 @@  static int flush_pending(struct metadump_struct *md, int done)
 	struct async_work *async = NULL;
 	struct extent_buffer *eb;
 	u64 blocksize = md->root->nodesize;
-	u64 start;
+	u64 start = 0;
 	u64 size;
 	size_t offset;
 	int ret = 0;