Skip to contentSkip to conversation

block/block-copy: Fix uninitialized variable in block_copy_task_entry

PATCH Applied Philippe Mathieu-Daudé 3 participants 7 messages May 7, 2020 – May 14, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

cover block/block-copy: Fix uninitialized variable in block_copy_task_entry

block_copy_task_entry() might be written differently to avoid the initialization. This silents the warning and let me build.

Philippe Mathieu-Daudé (2):
block/block-copy: Fix uninitialized variable in block_copy_task_entry block/block-copy: Simplify block_copy_do_copy()

 block/block-copy.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
Signature · 1 line
2.21.3
#1 lore raw

PATCH 1/2 block/block-copy: Fix uninitialized variable in block_copy_task_entry

Fix when building with -Os:

CC block/block-copy.o
block/block-copy.c: In function ‘block_copy_task_entry’:
block/block-copy.c:428:38: error: ‘error_is_read’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

    428 |         t->call_state->error_is_read = error_is_read;
        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
---
 block/block-copy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/block-copy.c +1 -1
index 03500680f7..83e16c89d9 100644
@@ -418,7 +418,7 @@ out:
 static coroutine_fn int block_copy_task_entry(AioTask *task)
 {
     BlockCopyTask *t = container_of(task, BlockCopyTask, task);
-    bool error_is_read;
+    bool error_is_read = false;
     int ret;
 
     ret = block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes,
Signature · 1 line
2.21.3
Reviewed-by on v1 1/2
#2 lore raw
Quoted 8 lines · Philippe Mathieu-Daudé

Fix when building with -Os:

CC block/block-copy.o
block/block-copy.c: In function ‘block_copy_task_entry’:

   block/block-copy.c:428:38: error: ‘error_is_read’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     428 |         t->call_state->error_is_read = error_is_read;
         |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~

Looks like -Os triggered different inlining of block_copy_do_copy(). I confirm that block_copy_do_copy does NOT initialize error_is_read except when returning < 0, but similarly block_copy_task_entry() does not read error_is_read except in the same setups. So it looks like no actual bug was triggered, but we can definitely aid the compiler's analysis by initializing.

Quoted 4 lines
---
  block/block-copy.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw

PATCH 2/2 block/block-copy: Simplify block_copy_do_copy()

In reply to Philippe Mathieu-Daudé

block_copy_do_copy() is static, only used in block_copy_task_entry with the error_is_read argument set. No need to check for it, simplify.

---
 block/block-copy.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
block/block-copy.c +3 -9
index 83e16c89d9..e8455b817a 100644
@@ -343,9 +343,7 @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
                                     ~BDRV_REQ_WRITE_COMPRESSED);
         if (ret < 0) {
             trace_block_copy_write_zeroes_fail(s, offset, ret);
-            if (error_is_read) {
-                *error_is_read = false;
-            }
+            *error_is_read = false;
         }
         return ret;
     }
@@ -393,9 +391,7 @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
     ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0);
     if (ret < 0) {
         trace_block_copy_read_fail(s, offset, ret);
-        if (error_is_read) {
-            *error_is_read = true;
-        }
+        *error_is_read = true;
         goto out;
     }
 
@@ -403,9 +399,7 @@ static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
                          s->write_flags);
     if (ret < 0) {
         trace_block_copy_write_fail(s, offset, ret);
-        if (error_is_read) {
-            *error_is_read = false;
-        }
+        *error_is_read = false;
         goto out;
     }
 
Signature · 1 line
2.21.3
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] block/block-copy: Simplify block_copy_do_copy()

Quoted 8 lines · Philippe Mathieu-Daudé

block_copy_do_copy() is static, only used in block_copy_task_entry with the error_is_read argument set. No need to check for it, simplify.

---
  block/block-copy.c | 12 +++---------
  1 file changed, 3 insertions(+), 9 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

block_copy_task_entry() might be written differently to avoid the initialization. This silents the warning and let me build.

Philippe Mathieu-Daudé (2):
block/block-copy: Fix uninitialized variable in block_copy_task_entry block/block-copy: Simplify block_copy_do_copy()

  block/block-copy.c | 14 ++++----------
  1 file changed, 4 insertions(+), 10 deletions(-)

ping?

Applied
#6 lore raw
In reply to Philippe Mathieu-Daudé

Am 07.05.2020 um 14:11 hat Philippe Mathieu-Daudé geschrieben:

Quoted 2 lines

block_copy_task_entry() might be written differently to avoid the initialization. This silents the warning and let me build.

Thanks, applied to the block branch.

Kevin