Skip to contentSkip to conversation

block: Fix compiler warning (-Werror=uninitialized)

PATCH Applied Stefan Weil 4 participants 5 messages Sep 17, 2013 – Sep 20, 2013 Block layer

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Fix compiler warning (-Werror=uninitialized)

The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Now 'copy' has always a defined value, so the check for ret >= 0 can be removed.

---
 block/stream.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/stream.c +2 -3
index 078ce4a..fc19194 100644
@@ -108,7 +108,7 @@ static void coroutine_fn stream_run(void *opaque)
 
     for (sector_num = 0; sector_num < end; sector_num += n) {
         uint64_t delay_ns = 0;
-        bool copy;
+        bool copy = false;
 
 wait:
         /* Note that even when no rate limit is applied we need to yield
@@ -123,7 +123,6 @@ wait:
                                 STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
-            copy = false;
         } else if (ret >= 0) {
             /* Copy if allocated in the intermediate images.  Limit to the
              * known-unallocated area [sector_num, sector_num+n).  */
@@ -138,7 +137,7 @@ wait:
             copy = (ret == 1);
         }
         trace_stream_one_iteration(s, sector_num, n, ret);
-        if (ret >= 0 && copy) {
+        if (copy) {
             if (s->common.speed) {
                 delay_ns = ratelimit_calculate_delay(&s->limit, n);
                 if (delay_ns > 0) {
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Stefan Weil

The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Quoted 7 lines

Now 'copy' has always a defined value, so the check for ret >= 0 can be removed.

---
 block/stream.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan

#2 lore raw
In reply to Stefan Weil

Am 17.09.2013 18:43, schrieb Stefan Weil:

Quoted 29 lines

The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Now 'copy' has always a defined value, so the check for ret >= 0 can be removed.

---
 block/stream.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/stream.c +1 -1
index 078ce4a..fc19194 100644
@@ -108,7 +108,7 @@ static void coroutine_fn stream_run(void *opaque)
 
     for (sector_num = 0; sector_num < end; sector_num += n) {
         uint64_t delay_ns = 0;
-        bool copy;
+        bool copy = false;
 
 wait:
         /* Note that even when no rate limit is applied we need to yield

block/stream.c wait: · line 128

Quoted 7 lines
block/stream.c +0 -1
@@ -123,7 +123,6 @@ wait:
                                 STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
-            copy = false;
         } else if (ret >= 0) {
             /* Copy if allocated in the intermediate images.  Limit to the
              * known-unallocated area [sector_num, sector_num+n).  */

Sorry for not spotting this patch earlier. This hunk looks wrong and needs to be dropped, I believe. In the ret >= 0 && copy case, there is a "goto wait" which would now no longer be able to go from copy == true -> copy == false. Not sure if that can happen in practice.

Andreas

Quoted 10 lines
block/stream.c +1 -1
@@ -138,7 +137,7 @@ wait:
             copy = (ret == 1);
         }
         trace_stream_one_iteration(s, sector_num, n, ret);
-        if (ret >= 0 && copy) {
+        if (copy) {
             if (s->common.speed) {
                 delay_ns = ratelimit_calculate_delay(&s->limit, n);
                 if (delay_ns > 0) {
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

Il 19/09/2013 18:59, Andreas Färber ha scritto:

Quoted 27 lines

Am 17.09.2013 18:43, schrieb Stefan Weil:

Quoted 26 lines

The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Now 'copy' has always a defined value, so the check for ret >= 0 can be removed.

---
 block/stream.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/stream.c +1 -1
index 078ce4a..fc19194 100644
@@ -108,7 +108,7 @@ static void coroutine_fn stream_run(void *opaque)
 
     for (sector_num = 0; sector_num < end; sector_num += n) {
         uint64_t delay_ns = 0;
-        bool copy;
+        bool copy = false;
 
Quoted 15 lines

block/stream.c wait: · line 128

Quoted 10 lines
block/stream.c +0 -1
 wait:
         /* Note that even when no rate limit is applied we need to yield
@@ -123,7 +123,6 @@ wait:
                                 STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
-            copy = false;
         } else if (ret >= 0) {
             /* Copy if allocated in the intermediate images.  Limit to the
              * known-unallocated area [sector_num, sector_num+n).  */

Sorry for not spotting this patch earlier. This hunk looks wrong and needs to be dropped, I believe. In the ret >= 0 && copy case, there is a "goto wait" which would now no longer be able to go from copy == true -> copy == false. Not sure if that can happen in practice.

Yes, if the guest writes to the area that the job is copying. It wouldn't cause any data corruption, only do useless work on those sectors. A better patch would thus remove the initializer and move the "copy = false" before "if (ret == 1)".

Paolo

Quoted 14 lines

Andreas

Quoted 10 lines
block/stream.c +1 -1
@@ -138,7 +137,7 @@ wait:
             copy = (ret == 1);
         }
         trace_stream_one_iteration(s, sector_num, n, ret);
-        if (ret >= 0 && copy) {
+        if (copy) {
             if (s->common.speed) {
                 delay_ns = ratelimit_calculate_delay(&s->limit, n);
                 if (delay_ns > 0) {
#4 lore raw
In reply to Andreas Färber
Quoted 27 lines · Andreas Färber

Am 17.09.2013 18:43, schrieb Stefan Weil:

Quoted 26 lines

The patch fixes a warning from gcc (Debian 4.6.3-14+rpi1) 4.6.3:

block/stream.c:141:22: error:
‘copy’ may be used uninitialized in this function [-Werror=uninitialized]

This is not a real bug - a better compiler would not complain.

Now 'copy' has always a defined value, so the check for ret >= 0 can be removed.

---
 block/stream.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
block/stream.c +1 -1
index 078ce4a..fc19194 100644
@@ -108,7 +108,7 @@ static void coroutine_fn stream_run(void *opaque)
 
     for (sector_num = 0; sector_num < end; sector_num += n) {
         uint64_t delay_ns = 0;
-        bool copy;
+        bool copy = false;
 
Quoted 15 lines

block/stream.c wait: · line 128

Quoted 10 lines
block/stream.c +0 -1
 wait:
         /* Note that even when no rate limit is applied we need to yield
@@ -123,7 +123,6 @@ wait:
                                 STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n);
         if (ret == 1) {
             /* Allocated in the top, no need to copy.  */
-            copy = false;
         } else if (ret >= 0) {
             /* Copy if allocated in the intermediate images.  Limit to the
              * known-unallocated area [sector_num, sector_num+n).  */

Sorry for not spotting this patch earlier. This hunk looks wrong and needs to be dropped, I believe. In the ret >= 0 && copy case, there is a "goto wait" which would now no longer be able to go from copy == true -> copy == false. Not sure if that can happen in practice.

Thanks for catching this!

I've dropped the patch from my block tree for now.

Stefan