Skip to contentSkip to conversation

block: Remove unused assignment (fixes warning from clang)

PATCH Applied Stefan Weil 4 participants 5 messages Sep 28, 2013 – Sep 30, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Remove unused assignment (fixes warning from clang)

blockdev.c:1929:13: warning: Value stored to 'ret' is never read

            ret = 0;
            ^     ~
---
 blockdev.c |    1 -
 1 file changed, 1 deletion(-)
blockdev.c +0 -1
index 8aa66a9..8c83f6f 100644
@@ -1926,7 +1926,6 @@ void qmp_drive_mirror(const char *device, const char *target,
     } else {
         switch (mode) {
         case NEW_IMAGE_MODE_EXISTING:
-            ret = 0;
             break;
         case NEW_IMAGE_MODE_ABSOLUTE_PATHS:
             /* create new image with backing file */
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 3 lines · Stefan Weil

blockdev.c:1929:13: warning: Value stored to 'ret' is never read

             ret = 0;
             ^     ~

Applied to the trivial patches queue.

Quoted 10 lines
---
  blockdev.c |    1 -
  1 file changed, 1 deletion(-)
blockdev.c +0 -0
index 8aa66a9..8c83f6f 100644

blockdev.c void qmp_drive_mirror(const char *device, const char *target, · line 1929

Quoted 5 lines
blockdev.c +0 -1
@@ -1926,7 +1926,6 @@ void qmp_drive_mirror(const char *device, const char *target,
      } else {
          switch (mode) {
          case NEW_IMAGE_MODE_EXISTING:
-            ret = 0;
              break;

While this one is obviously unused assignment,
there's on more usage of `ret' variable in this
function, -- it is to store the return value
from bdrv_open():

    ret = bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKING, drv,
                    &local_err);
    if (ret < 0) {...

What's the rule about converting that into if() ?

Thanks,

/mjt

#2 lore raw

Am 29.09.2013 21:44, schrieb Michael Tokarev:

Quoted 1 line

28.09.2013 13:55, Stefan Weil wrote:

[...]

Quoted 19 lines

blockdev.c void qmp_drive_mirror(const char *device, const · line 1930

Quoted 11 lines
blockdev.c +0 -1
index 8aa66a9..8c83f6f 100644
@@ -1926,7 +1926,6 @@ void qmp_drive_mirror(const char *device, const
 char *target,
      } else {
          switch (mode) {
          case NEW_IMAGE_MODE_EXISTING:
-            ret = 0;
              break;

While this one is obviously unused assignment,
there's on more usage of `ret' variable in this
function, -- it is to store the return value
from bdrv_open():

ret = bdrv_open(target_bs, target, NULL, flags |
BDRV_O_NO_BACKING, drv,

Quoted 8 lines
                    &local_err);
    if (ret < 0) {...

What's the rule about converting that into if() ?

Thanks,

/mjt

Is there a rule for cases like that? This pattern is very common in QEMU code
(several occurrences in blockdev.c). Should we eliminate the 'ret' variable? I don't think it's worth the effort.

Stefan

#3 lore raw

Am 29.09.2013 um 22:15 hat Stefan Weil geschrieben:

Quoted 27 lines

Am 29.09.2013 21:44, schrieb Michael Tokarev:

Quoted 1 line

28.09.2013 13:55, Stefan Weil wrote:

[...]

Quoted 24 lines

blockdev.c void qmp_drive_mirror(const char *device, const · line 1930

Quoted 11 lines
blockdev.c +0 -1
index 8aa66a9..8c83f6f 100644
@@ -1926,7 +1926,6 @@ void qmp_drive_mirror(const char *device, const
 char *target,
      } else {
          switch (mode) {
          case NEW_IMAGE_MODE_EXISTING:
-            ret = 0;
              break;

While this one is obviously unused assignment,
there's on more usage of `ret' variable in this
function, -- it is to store the return value
from bdrv_open():

ret = bdrv_open(target_bs, target, NULL, flags |
BDRV_O_NO_BACKING, drv,

                    &local_err);
    if (ret < 0) {...

What's the rule about converting that into if() ?

Quoted 8 lines
Quoted 3 lines

Thanks,

/mjt

Is there a rule for cases like that? This pattern is very common in QEMU code
(several occurrences in blockdev.c). Should we eliminate the 'ret' variable? I don't think it's worth the effort.

And actually I think removing it would make the code worse (less readable).

Kevin

#4 lore raw
In reply to Stefan Weil
Quoted 27 lines · Stefan Weil

Am 29.09.2013 21:44, schrieb Michael Tokarev:

Quoted 1 line

28.09.2013 13:55, Stefan Weil wrote:

[...]

Quoted 24 lines

blockdev.c void qmp_drive_mirror(const char *device, const · line 1930

Quoted 11 lines
blockdev.c +0 -1
index 8aa66a9..8c83f6f 100644
@@ -1926,7 +1926,6 @@ void qmp_drive_mirror(const char *device, const
 char *target,
      } else {
          switch (mode) {
          case NEW_IMAGE_MODE_EXISTING:
-            ret = 0;
              break;

While this one is obviously unused assignment,
there's on more usage of `ret' variable in this
function, -- it is to store the return value
from bdrv_open():

ret = bdrv_open(target_bs, target, NULL, flags |
BDRV_O_NO_BACKING, drv,

                    &local_err);
    if (ret < 0) {...

What's the rule about converting that into if() ?

Quoted 8 lines
Quoted 3 lines

Thanks,

/mjt

Is there a rule for cases like that? This pattern is very common in QEMU code
(several occurrences in blockdev.c). Should we eliminate the 'ret' variable? I don't think it's worth the effort.

Me neither. There is a minor style difference between putting everything into the if statement and using a variable to split up a potentially complicated if statement.

Both approaches are usually okay.

Stefan