Skip to contentSkip to conversation

misc: Trivial static code analyzer fixes

PATCH Superseded Philippe Mathieu-Daudé 6 participants 28 messages Mar 21, 2020

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover misc: Trivial static code analyzer fixes

Fix trivial warnings reported by the Clang static code analyzer.

Philippe Mathieu-Daudé (11):
block: Remove dead assignment
blockdev: Remove dead assignment
hw/i2c/pm_smbus: Remove dead assignment
hw/input/adb-kbd: Remove dead assignment
hw/ide/sii3112: Remove dead assignment
hw/isa/i82378: Remove dead assignment
hw/gpio/aspeed_gpio: Remove dead assignment hw/timer/exynos4210_mct: Remove dead assignments hw/timer/stm32f2xx_timer: Remove dead assignment hw/timer/pxa2xx_timer: Add assertion to silent static analyzer warning hw/scsi/esp-pci: Remove dead assignment

 block.c                    | 2 +-
 blockdev.c                 | 2 +-
 hw/gpio/aspeed_gpio.c      | 4 ++--
 hw/i2c/pm_smbus.c          | 1 -
 hw/ide/sii3112.c           | 2 +-
 hw/input/adb-kbd.c         | 1 -
 hw/isa/i82378.c            | 8 ++++----
 hw/scsi/esp-pci.c          | 1 -
 hw/timer/exynos4210_mct.c  | 3 ---
 hw/timer/pxa2xx_timer.c    | 1 +
 hw/timer/stm32f2xx_timer.c | 1 -
 11 files changed, 10 insertions(+), 16 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/11 block: Remove dead assignment

Fix warning reported by Clang static code analyzer:

block.c:3167:5: warning: Value stored to 'ret' is never read

      ret = bdrv_fill_options(&options, filename, &flags, &local_err);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
index a2542c977b..908c109a8c 100644
@@ -3164,7 +3164,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
                                     parent->open_flags, parent->options);
     }
 
-    ret = bdrv_fill_options(&options, filename, &flags, &local_err);
+    bdrv_fill_options(&options, filename, &flags, &local_err);
     if (local_err) {
         goto fail;
     }
Signature · 1 line
2.21.1
#2 lore raw

Re: [PATCH-for-5.0 01/11] block: Remove dead assignment

12:49 PM Sub, 21.03.2020. Philippe Mathieu-Daudé <[email protected]> је написао/ла:

Quoted 8 lines

Fix warning reported by Clang static code analyzer:

block.c:3167:5: warning: Value stored to 'ret' is never read

      ret = bdrv_fill_options(&options, filename, &flags, &local_err);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer

Peter, and others,

Is this allowed use of "Reported-by:" mark?

I did not notice it being used this way before. And was under impression that all similar tags/marks must be followed by a person, not a tool.

Regards,
Aleksandar

block.c static BlockDriverState *bdrv_open_inherit(const

Quoted 10 lines
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index a2542c977b..908c109a8c 100644
@@ -3164,7 +3164,7 @@ static BlockDriverState *bdrv_open_inherit(const

char *filename,

Quoted 12 lines
block.c +1 -2
                                     parent->open_flags, parent->options);
     }
 
-    ret = bdrv_fill_options(&options, filename, &flags, &local_err);
+    bdrv_fill_options(&options, filename, &flags, &local_err);
     if (local_err) {
         goto fail;
     }
--

2.21.1

#3 lore raw

Re: [PATCH-for-5.0 01/11] block: Remove dead assignment

Quoted 9 lines · Aleksandar Markovic

12:49 PM Sub, 21.03.2020. Philippe Mathieu-Daudé <[email protected]> је написао/ла:

Quoted 7 lines

Fix warning reported by Clang static code analyzer:

block.c:3167:5: warning: Value stored to 'ret' is never read

      ret = bdrv_fill_options(&options, filename, &flags, &local_err);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 8 lines
Quoted 1 line
Reported-by Clang Static Analyzer

Peter, and others,

Is this allowed use of "Reported-by:" mark?

I did not notice it being used this way before. And was under impression that all similar tags/marks must be followed by a person, not a tool.

I think there were previous patches with Reported-by: Euler Robot which may be similar to this usage.

Regards,
BALATON Zoltan

Quoted 28 lines

Regards,
Aleksandar

block.c static BlockDriverState *bdrv_open_inherit(const

Quoted 10 lines
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index a2542c977b..908c109a8c 100644
@@ -3164,7 +3164,7 @@ static BlockDriverState *bdrv_open_inherit(const

char *filename,

Quoted 12 lines
block.c +1 -2
                                     parent->open_flags, parent->options);
     }
 
-    ret = bdrv_fill_options(&options, filename, &flags, &local_err);
+    bdrv_fill_options(&options, filename, &flags, &local_err);
     if (local_err) {
         goto fail;
     }
--

2.21.1

#4 lore raw

Re: [PATCH-for-5.0 01/11] block: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Le 21/03/2020 à 12:46, Philippe Mathieu-Daudé a écrit :

Quoted 18 lines

Fix warning reported by Clang static code analyzer:

block.c:3167:5: warning: Value stored to 'ret' is never read

      ret = bdrv_fill_options(&options, filename, &flags, &local_err);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index a2542c977b..908c109a8c 100644

block.c static BlockDriverState *bdrv_open_inherit(const char *filename, · line 3170

Quoted 8 lines
block.c +1 -1
@@ -3164,7 +3164,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
                                     parent->open_flags, parent->options);
     }
 
-    ret = bdrv_fill_options(&options, filename, &flags, &local_err);
+    bdrv_fill_options(&options, filename, &flags, &local_err);
     if (local_err) {
         goto fail;
     }

I would be sruprised if coverity doesn't warn about an unused return value.

Thanks,
Laurent

#5 lore raw

Re: [PATCH-for-5.0 01/11] block: Remove dead assignment

Quoted 21 lines · Laurent Vivier

Le 21/03/2020 à 12:46, Philippe Mathieu-Daudé a écrit :

Quoted 20 lines

Fix warning reported by Clang static code analyzer:

block.c:3167:5: warning: Value stored to 'ret' is never read

      ret = bdrv_fill_options(&options, filename, &flags, &local_err);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index a2542c977b..908c109a8c 100644
@@ -3164,7 +3164,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
                                     parent->open_flags, parent->options);
     }
 
Quoted 8 lines

block.c static BlockDriverState *bdrv_open_inherit(const char *filename, · line 3170

Quoted 6 lines
block.c +1 -1
-    ret = bdrv_fill_options(&options, filename, &flags, &local_err);
+    bdrv_fill_options(&options, filename, &flags, &local_err);
     if (local_err) {
         goto fail;
     }

I would be sruprised if coverity doesn't warn about an unused return value.

Coverity recognizes the fact that some return values can be safely ignored, and reports only ignored return values it sees commonly checked elsewhere.

This function is used called nowhere else. Coverity won't complain.

However, I'd prefer

        ret = bdrv_fill_options(&options, filename, &flags, &local_err);
   -    if (local_err) {
   +    if (ret < 0) {
            goto fail;
        }
#6 lore raw

PATCH 2/11 blockdev: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC blockdev.o
blockdev.c:2744:5: warning: Value stored to 'ret' is never read

      ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp);
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 blockdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
blockdev.c +1 -1
index fa8630cb41..6effd5afaa 100644
@@ -2741,7 +2741,7 @@ void qmp_block_resize(bool has_device, const char *device,
     }
 
     bdrv_drained_begin(bs);
-    ret = blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp);
+    blk_truncate(blk, size, false, PREALLOC_MODE_OFF, errp);
     bdrv_drained_end(bs);
 
 out:
Signature · 1 line
2.21.1
#7 lore raw

PATCH 3/11 hw/i2c/pm_smbus: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/i2c/pm_smbus.o
hw/i2c/pm_smbus.c:187:17: warning: Value stored to 'ret' is never read

                  ret = 0;
                  ^     ~
Reported-by Clang Static Analyzer
---
 hw/i2c/pm_smbus.c | 1 -
 1 file changed, 1 deletion(-)
hw/i2c/pm_smbus.c +0 -1
index 36994ff585..4728540c37 100644
@@ -184,7 +184,6 @@ static void smb_transaction(PMSMBus *s)
                 s->smb_stat |= STS_HOST_BUSY | STS_BYTE_DONE;
                 s->smb_data[0] = s->smb_blkdata;
                 s->smb_index = 0;
-                ret = 0;
             }
             goto out;
         }
Signature · 1 line
2.21.1
#8 lore raw

PATCH 4/11 hw/input/adb-kbd: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/input/adb-kbd.o
hw/input/adb-kbd.c:200:5: warning: Value stored to 'olen' is never read

      olen = 0;
      ^      ~
Reported-by Clang Static Analyzer
---
 hw/input/adb-kbd.c | 1 -
 1 file changed, 1 deletion(-)
hw/input/adb-kbd.c +0 -1
index 0ba8207589..b0565be21b 100644
@@ -197,7 +197,6 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)
     int keycode;
     int olen;
 
-    olen = 0;
     if (s->count == 0) {
         return 0;
     }
Signature · 1 line
2.21.1
#9 lore raw

Re: [PATCH-for-5.0 04/11] hw/input/adb-kbd: Remove dead assignment

Quoted 18 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/input/adb-kbd.o
hw/input/adb-kbd.c:200:5: warning: Value stored to 'olen' is never read

     olen = 0;
     ^      ~
Reported-by Clang Static Analyzer

---
hw/input/adb-kbd.c | 1 -

1 file changed, 1 deletion(-)
hw/input/adb-kbd.c +0 -0
index 0ba8207589..b0565be21b 100644

hw/input/adb-kbd.c static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf) · line 202

Quoted 7 lines
hw/input/adb-kbd.c +0 -1
@@ -197,7 +197,6 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)
    int keycode;
    int olen;
 
-    olen = 0;
    if (s->count == 0) {
        return 0;
    }

Is this variable still needed at all? Looks like it's a remnant after a1f4971863 that can now only return 0 or 2 so you could just remove this variable and return 2 where now it's assigned as 2 or change return olen at the end to return 2 or maybe keep olen and change the return 0 above to return olen to silence warning but I think this could be cleaned up.

Regards,
BALATON Zoltan

#10 lore raw

PATCH 5/11 hw/ide/sii3112: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

    CC      hw/ide/sii3112.o
  hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read
          val = 0;
          ^     ~
Reported-by Clang Static Analyzer
---
 hw/ide/sii3112.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +1 -1
index 06605d7af2..36f1905ddb 100644
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr addr,
         val = (uint32_t)d->regs[1].sien << 16;
         break;
     default:
-        val = 0;
+        break;
     }
     trace_sii3112_read(size, addr, val);
     return val;
Signature · 1 line
2.21.1
Reviewed-by on v1 5/11
#11 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

Quoted 18 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

   CC      hw/ide/sii3112.o
 hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read
         val = 0;
         ^     ~
Reported-by Clang Static Analyzer

---
hw/ide/sii3112.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +0 -0
index 06605d7af2..36f1905ddb 100644

hw/ide/sii3112.c static uint64_t sii3112_reg_read(void *opaque, hwaddr addr, · line 131

Quoted 8 lines
hw/ide/sii3112.c +1 -1
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr addr,
        val = (uint32_t)d->regs[1].sien << 16;
        break;
    default:
-        val = 0;
+        break;
    }
    trace_sii3112_read(size, addr, val);
    return val;

Value is clearly used in trace and return so don't really get why the compiler complains here. Looks like wrong warning to me. It's true however that since val is init to 0 at the beginning this assignment is not strictily needed and this should work as well, so

Regards,
BALATON Zoltan

#12 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

    CC      hw/ide/sii3112.o
  hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read
          val = 0;
          ^     ~
Reported-by Clang Static Analyzer
---
 hw/ide/sii3112.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +0 -0
index 06605d7af2..36f1905ddb 100644

hw/ide/sii3112.c static uint64_t sii3112_reg_read(void *opaque, hwaddr · line 129

Quoted 6 lines
hw/ide/sii3112.c +1 -1
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr
 addr,
         val = (uint32_t)d->regs[1].sien << 16;
         break;
     default:
-        val = 0;
+        break;

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

Regards,
Aleksandar

Quoted 8 lines
hw/ide/sii3112.c +0 -0
     }
     trace_sii3112_read(size, addr, val);
     return val;

--
2.21.1

#13 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

Quoted 29 lines · Aleksandar Markovic
Quoted 18 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

    CC      hw/ide/sii3112.o
  hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read
          val = 0;
          ^     ~
Reported-by Clang Static Analyzer
---
 hw/ide/sii3112.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +0 -0
index 06605d7af2..36f1905ddb 100644

hw/ide/sii3112.c static uint64_t sii3112_reg_read(void *opaque, hwaddr · line 129

Quoted 6 lines
hw/ide/sii3112.c +1 -1
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr
 addr,
         val = (uint32_t)d->regs[1].sien << 16;
         break;
     default:
-        val = 0;
+        break;
Quoted 6 lines

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

Oh, actually I think the warning was for that statement not for the one patched as it makes more sense there where val is assigned in void sii3112_reg_write() where it's indeed not used so maybe that was meant to be patched instead?

Regards,
BALATON Zoltan

#14 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

Quoted 38 lines · BALATON Zoltan
Quoted 30 lines · Aleksandar Markovic
Quoted 18 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

    CC      hw/ide/sii3112.o
  hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read val = 0;
          ^     ~

Reported-by Clang Static Analyzer

---
 hw/ide/sii3112.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +0 -0
index 06605d7af2..36f1905ddb 100644
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, 
Quoted 7 lines

hwaddr
addr,
         val = (uint32_t)d->regs[1].sien << 16;
         break;
     default:
-        val = 0;
+        break;

Quoted 6 lines

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

Quoted 1 line

Oh, actually I think the warning was for that statement not for the one patched as it makes more sense there where val is assigned in void sii3112_reg_write() where it's indeed not used so maybe that was meant to be patched instead?

Ah, the warning is for hw/ide/sii3112.c:204 but I incorrectly patched hw/ide/sii3112.c:128 =)

Quoted 3 lines

Regards,
BALATON Zoltan

#15 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

Quoted 38 lines · Philippe Mathieu-Daudé
Quoted 37 lines · BALATON Zoltan
Quoted 35 lines · Aleksandar Markovic
Quoted 21 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

    CC      hw/ide/sii3112.o
  hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read val = 0;
          ^     ~

Reported-by Clang Static Analyzer

---
 hw/ide/sii3112.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ide/sii3112.c +0 -0
index 06605d7af2..36f1905ddb 100644
@@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr
 addr,
          val = (uint32_t)d->regs[1].sien << 16;
          break;
Quoted 3 lines

     default:
-        val = 0;
+        break;

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

Quoted 3 lines
Quoted 1 line

Oh, actually I think the warning was for that statement not for the one patched as it makes more sense there where val is assigned in void sii3112_reg_write() where it's indeed not used so maybe that was meant to be patched instead?

Ah, the warning is for hw/ide/sii3112.c:204 but I incorrectly patched hw/ide/sii3112.c:128 =)

Now you may patch both to replace val = 0 with break to keep symmetry. My Reviewed-by stands (even if apparently not much use). Thanks for Aleksandar for spotting it.

Regards,
BALATON Zoltan

#16 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

In reply to Aleksandar Markovic
Quoted 31 lines · Aleksandar Markovic

On Saturday, March 21, 2020, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

    Fix warning reported by Clang static code analyzer:

         CC      hw/ide/sii3112.o
       hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read
               val = 0;
               ^     ~

    Reported-by: Clang Static Analyzer
    Signed-off-by: Philippe Mathieu-Daudé <[email protected]
    <mailto:[email protected]>>
    ---
      hw/ide/sii3112.c | 2 +-
      1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c
    index 06605d7af2..36f1905ddb 100644
    --- a/hw/ide/sii3112.c
    +++ b/hw/ide/sii3112.c
    @@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque,
    hwaddr addr,
              val = (uint32_t)d->regs[1].sien << 16;
              break;
          default:
    -        val = 0;
    +        break;
Quoted 1 line

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

No clue why there is no warnings emitted for sii3112_reg_write()...

Do you mind sending a patch?

Quoted 11 lines

Regards,
Aleksandar

          }
          trace_sii3112_read(size, addr, val);
          return val;
    -- 
    2.21.1
#17 lore raw

Re: [PATCH-for-5.0 05/11] hw/ide/sii3112: Remove dead assignment

Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 31 lines · Aleksandar Markovic

On Saturday, March 21, 2020, Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

    Fix warning reported by Clang static code analyzer:

         CC      hw/ide/sii3112.o
       hw/ide/sii3112.c:204:9: warning: Value stored to 'val' is never read val = 0;
               ^     ~

Reported-by Clang Static Analyzer

    <mailto:[email protected]>>
    ---
      hw/ide/sii3112.c | 2 +-

      1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c
    index 06605d7af2..36f1905ddb 100644
    --- a/hw/ide/sii3112.c
    +++ b/hw/ide/sii3112.c
    @@ -125,7 +125,7 @@ static uint64_t sii3112_reg_read(void *opaque, hwaddr addr,
              val = (uint32_t)d->regs[1].sien << 16;
              break;
          default:
    -        val = 0;
    +        break;

Quoted 5 lines
Quoted 1 line

There is another function in the same file, having a similar switch statement. There is no warning for that second tunction, since "val" is its parameter, not a local varioble, like is the case here. This means that the proposed change introduces inconsistency between two functions, therefore it is better to remove the initialization of "val" to 0, than to remove this line in "default" section.

No clue why there is no warnings emitted for sii3112_reg_write()...

Do you mind sending a patch?

Don't worry I'll follow up.

Quoted 11 lines
Quoted 11 lines

Regards,
Aleksandar

          }
          trace_sii3112_read(size, addr, val);
          return val;
    --     2.21.1

#18 lore raw

PATCH 6/11 hw/isa/i82378: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Rename the unique variable assigned as 'pit' which better represents what it holds, to fix a warning reported by the Clang static code analyzer:

    CC      hw/isa/i82378.o
  hw/isa/i82378.c:108:5: warning: Value stored to 'isa' is never read
      isa = isa_create_simple(isabus, "i82374");
      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/isa/i82378.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/isa/i82378.c +4 -4
index dcb6b479ea..d9e6c7fa00 100644
@@ -67,7 +67,7 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     I82378State *s = I82378(dev);
     uint8_t *pci_conf;
     ISABus *isabus;
-    ISADevice *isa;
+    ISADevice *pit;
 
     pci_conf = pci->config;
     pci_set_word(pci_conf + PCI_COMMAND,
@@ -99,13 +99,13 @@ static void i82378_realize(PCIDevice *pci, Error **errp)
     isa_bus_irqs(isabus, s->i8259);
 
     /* 1 82C54 (pit) */
-    isa = i8254_pit_init(isabus, 0x40, 0, NULL);
+    pit = i8254_pit_init(isabus, 0x40, 0, NULL);
 
     /* speaker */
-    pcspk_init(isabus, isa);
+    pcspk_init(isabus, pit);
 
     /* 2 82C37 (dma) */
-    isa = isa_create_simple(isabus, "i82374");
+    isa_create_simple(isabus, "i82374");
 }
 
 static void i82378_init(Object *obj)
Signature · 1 line
2.21.1
#19 lore raw

PATCH 7/11 hw/gpio/aspeed_gpio: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during its initialization is never read

      int set_idx, g_idx = *group_idx;
                   ^~~~~   ~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/gpio/aspeed_gpio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/gpio/aspeed_gpio.c +2 -2
index 41e11ea9b0..cc07ab9866 100644
@@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data,
 static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx)
 {
     AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
-    int set_idx, g_idx = *group_idx;
+    int set_idx;
 
     for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) {
         const GPIOSetProperties *set_props = &agc->props[set_idx];
-        for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {
+        for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {
             if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) {
                 *group_idx = g_idx;
                 return set_idx;
Signature · 1 line
2.21.1
#20 lore raw

Re: [PATCH-for-5.0 07/11] hw/gpio/aspeed_gpio: Remove dead assignment

Quoted 17 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during its initialization is never read

     int set_idx, g_idx = *group_idx;
                  ^~~~~   ~~~~~~~~~~
Reported-by Clang Static Analyzer

---
hw/gpio/aspeed_gpio.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
hw/gpio/aspeed_gpio.c +0 -0
index 41e11ea9b0..cc07ab9866 100644

hw/gpio/aspeed_gpio.c static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data, · line 721

Quoted 10 lines
hw/gpio/aspeed_gpio.c +2 -2
@@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data,
 static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx)
 {
    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
-    int set_idx, g_idx = *group_idx;
+    int set_idx;
 
    for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) {
        const GPIOSetProperties *set_props = &agc->props[set_idx];
-        for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {
+        for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {

Is declaring variables here allowed by coding style? Shouldn't you only remove init value from above?

Regards,
BALATON Zoltan

Quoted 4 lines
hw/gpio/aspeed_gpio.c +0 -0
            if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) {
                *group_idx = g_idx;
                return set_idx;
#21 lore raw

Re: [PATCH-for-5.0 07/11] hw/gpio/aspeed_gpio: Remove dead assignment

Quoted 25 lines · BALATON Zoltan
Quoted 24 lines · Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

 hw/gpio/aspeed_gpio.c:717:18: warning: Value stored to 'g_idx' during its initialization is never read int set_idx, g_idx = *group_idx;
                  ^~~~~   ~~~~~~~~~~

Reported-by Clang Static Analyzer

---
hw/gpio/aspeed_gpio.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
hw/gpio/aspeed_gpio.c +1 -1
index 41e11ea9b0..cc07ab9866 100644
@@ -714,11 +714,11 @@ static void aspeed_gpio_write(void *opaque, 
 hwaddr offset, uint64_t data,
 static int get_set_idx(AspeedGPIOState *s, const char *group, int *group_idx)
 {
     AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
-    int set_idx, g_idx = *group_idx;
+    int set_idx;
 
Quoted 6 lines

hw/gpio/aspeed_gpio.c static void aspeed_gpio_write(void *opaque, hwaddr offset, uint64_t data, · line 721

Quoted 4 lines
hw/gpio/aspeed_gpio.c +1 -1
     for (set_idx = 0; set_idx < agc->nr_gpio_sets; set_idx++) {
         const GPIOSetProperties *set_props = &agc->props[set_idx];
-        for (g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {
+        for (int g_idx = 0; g_idx < ASPEED_GROUPS_PER_SET; g_idx++) {

Is declaring variables here allowed by coding style? Shouldn't you only remove init value from above?

You are right, it is not (yet?) allowed by QEMU coding style.

Quoted 8 lines

Regards,
BALATON Zoltan

Quoted 4 lines
hw/gpio/aspeed_gpio.c +0 -0
             if (!strncmp(group, set_props->group_label[g_idx], strlen(group))) {
                 *group_idx = g_idx;

                return set_idx;

#22 lore raw

PATCH 8/11 hw/timer/exynos4210_mct: Remove dead assignments

In reply to Philippe Mathieu-Daudé

Fix warnings reported by Clang static code analyzer:

hw/timer/exynos4210_mct.c:1370:9: warning: Value stored to 'index' is never read

        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
        ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/timer/exynos4210_mct.c:1399:9: warning: Value stored to 'index' is never read
        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
        ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  hw/timer/exynos4210_mct.c:1441:9: warning: Value stored to 'index' is never read
        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
        ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/timer/exynos4210_mct.c | 3 ---
 1 file changed, 3 deletions(-)
hw/timer/exynos4210_mct.c +0 -3
index 944120aea5..c0a25e71ec 100644
@@ -1367,7 +1367,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
 
     case L0_TCNTB: case L1_TCNTB:
         lt_i = GET_L_TIMER_IDX(offset);
-        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
 
         /*
          * TCNTB is updated to internal register only after CNT expired.
@@ -1396,7 +1395,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
 
     case L0_ICNTB: case L1_ICNTB:
         lt_i = GET_L_TIMER_IDX(offset);
-        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
 
         s->l_timer[lt_i].reg.wstat |= L_WSTAT_ICNTB_WRITE;
         s->l_timer[lt_i].reg.cnt[L_REG_CNT_ICNTB] = value &
@@ -1438,7 +1436,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
 
     case L0_FRCNTB: case L1_FRCNTB:
         lt_i = GET_L_TIMER_IDX(offset);
-        index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i);
 
         DPRINTF("local timer[%d] FRCNTB write %llx\n", lt_i, value);
 
Signature · 1 line
2.21.1
#23 lore raw

PATCH 9/11 hw/timer/stm32f2xx_timer: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/timer/stm32f2xx_timer.o
hw/timer/stm32f2xx_timer.c:225:9: warning: Value stored to 'value' is never read

          value = timer_val;
          ^       ~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/timer/stm32f2xx_timer.c | 1 -
 1 file changed, 1 deletion(-)
hw/timer/stm32f2xx_timer.c +0 -1
index 06ec8a02c2..ba8694dcd3 100644
@@ -222,7 +222,6 @@ static void stm32f2xx_timer_write(void *opaque, hwaddr offset,
     case TIM_PSC:
         timer_val = stm32f2xx_ns_to_ticks(s, now) - s->tick_offset;
         s->tim_psc = value & 0xFFFF;
-        value = timer_val;
         break;
     case TIM_CNT:
         timer_val = value;
Signature · 1 line
2.21.1
#24 lore raw

PATCH 10/11 hw/timer/pxa2xx_timer: Add assertion to silent static analyzer warning

In reply to Philippe Mathieu-Daudé

pxa2xx_timer_tick4() takes an opaque pointer, then calls pxa2xx_timer_update4(), so the static analyzer can not verify that the 'n < 8':

  425 static void pxa2xx_timer_tick4(void *opaque)
  426 {
  427     PXA2xxTimer4 *t = (PXA2xxTimer4 *) opaque;
  428     PXA2xxTimerInfo *i = (PXA2xxTimerInfo *) t->tm.info;
  429
  430     pxa2xx_timer_tick(&t->tm);
  433     if (t->control & (1 << 6))
  434         pxa2xx_timer_update4(i, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), t->tm.num - 4);

  135 static void pxa2xx_timer_update4(void *opaque, uint64_t now_qemu, int n)
  136 {
  137     PXA2xxTimerInfo *s = (PXA2xxTimerInfo *) opaque;
  140     static const int counters[8] = { 0, 0, 0, 0, 4, 4, 6, 6 };
  142
  143     if (s->tm4[n].control & (1 << 7))
  144         counter = n;
  145     else
  146         counter = counters[n];

Add an assert() to give the static analyzer a hint, this fixes a warning reported by Clang static code analyzer:

CC hw/timer/pxa2xx_timer.o
hw/timer/pxa2xx_timer.c:146:17: warning: Assigned value is garbage or undefined

          counter = counters[n];
                  ^ ~~~~~~~~~~~
Reported-by Clang Static Analyzer
---
 hw/timer/pxa2xx_timer.c | 1 +
 1 file changed, 1 insertion(+)
hw/timer/pxa2xx_timer.c +1 -0
index cd172cc1e9..944c165889 100644
@@ -140,6 +140,7 @@ static void pxa2xx_timer_update4(void *opaque, uint64_t now_qemu, int n)
     static const int counters[8] = { 0, 0, 0, 0, 4, 4, 6, 6 };
     int counter;
 
+    assert(n < ARRAY_SIZE(counters));
     if (s->tm4[n].control & (1 << 7))
         counter = n;
     else
Signature · 1 line
2.21.1
#25 lore raw

PATCH 11/11 hw/scsi/esp-pci: Remove dead assignment

In reply to Philippe Mathieu-Daudé

Fix warning reported by Clang static code analyzer:

CC hw/scsi/esp-pci.o
hw/scsi/esp-pci.c:198:9: warning: Value stored to 'size' is never read

          size = 4;
          ^      ~
Reported-by Clang Static Analyzer
---
 hw/scsi/esp-pci.c | 1 -
 1 file changed, 1 deletion(-)
hw/scsi/esp-pci.c +0 -1
index d5a1f9e017..2e6cc07d4e 100644
@@ -195,7 +195,6 @@ static void esp_pci_io_write(void *opaque, hwaddr addr,
         val <<= shift;
         val |= current & ~(mask << shift);
         addr &= ~3;
-        size = 4;
     }
 
     if (addr < 0x40) {
Signature · 1 line
2.21.1
#26 lore raw
In reply to Philippe Mathieu-Daudé

12:47 PM Sub, 21.03.2020. Philippe Mathieu-Daudé <[email protected]> је написао/ла:

Quoted 3 lines

Fix trivial warnings reported by the Clang static code analyzer.

Philippe,

It would be useful and customary for this type of fixes to provide here the environment you used for obtaining the warnings (clang version, configure parameters, and all needed elenents to repro the warnings).

Regards,
Aleksandar

Quoted 30 lines

Philippe Mathieu-Daudé (11):
block: Remove dead assignment
blockdev: Remove dead assignment
hw/i2c/pm_smbus: Remove dead assignment
hw/input/adb-kbd: Remove dead assignment
hw/ide/sii3112: Remove dead assignment
hw/isa/i82378: Remove dead assignment
hw/gpio/aspeed_gpio: Remove dead assignment hw/timer/exynos4210_mct: Remove dead assignments hw/timer/stm32f2xx_timer: Remove dead assignment hw/timer/pxa2xx_timer: Add assertion to silent static analyzer warning hw/scsi/esp-pci: Remove dead assignment

 block.c                    | 2 +-
 blockdev.c                 | 2 +-
 hw/gpio/aspeed_gpio.c      | 4 ++--
 hw/i2c/pm_smbus.c          | 1 -
 hw/ide/sii3112.c           | 2 +-
 hw/input/adb-kbd.c         | 1 -
 hw/isa/i82378.c            | 8 ++++----
 hw/scsi/esp-pci.c          | 1 -
 hw/timer/exynos4210_mct.c  | 3 ---
 hw/timer/pxa2xx_timer.c    | 1 +
 hw/timer/stm32f2xx_timer.c | 1 -
 11 files changed, 10 insertions(+), 16 deletions(-)

--
2.21.1

#27 lore raw
Quoted 8 lines · Aleksandar Markovic

12:47 PM Sub, 21.03.2020. Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> је написао/ла:

Quoted 3 lines

Fix trivial warnings reported by the Clang static code analyzer.

Philippe,

It would be useful and customary for this type of fixes to provide here the environment you used for obtaining the warnings (clang version, configure parameters, and all needed elenents to repro the warnings).

https://clang-analyzer.llvm.org/

$ sudo dnf install clang-analyzer
$ ../configure
$ scan-build make
Quoted 35 lines

Regards,
Aleksandar

Quoted 30 lines

Philippe Mathieu-Daudé (11):
  block: Remove dead assignment
  blockdev: Remove dead assignment
  hw/i2c/pm_smbus: Remove dead assignment
  hw/input/adb-kbd: Remove dead assignment
  hw/ide/sii3112: Remove dead assignment
  hw/isa/i82378: Remove dead assignment
  hw/gpio/aspeed_gpio: Remove dead assignment hw/timer/exynos4210_mct: Remove dead assignments hw/timer/stm32f2xx_timer: Remove dead assignment hw/timer/pxa2xx_timer: Add assertion to silent static analyzer warning hw/scsi/esp-pci: Remove dead assignment

 block.c                    | 2 +-
 blockdev.c                 | 2 +-
 hw/gpio/aspeed_gpio.c      | 4 ++--
 hw/i2c/pm_smbus.c          | 1 -
 hw/ide/sii3112.c           | 2 +-
 hw/input/adb-kbd.c         | 1 -
 hw/isa/i82378.c            | 8 ++++----
 hw/scsi/esp-pci.c          | 1 -
 hw/timer/exynos4210_mct.c  | 3 ---
 hw/timer/pxa2xx_timer.c    | 1 +
 hw/timer/stm32f2xx_timer.c | 1 -

 11 files changed, 10 insertions(+), 16 deletions(-)

--
2.21.1