redundant code: Fix warnings reported by Clang static code analyzer
v4 cover redundant code: Fix warnings reported by Clang static code analyzer
v1->v2:
- Patch1: Add John Snow review comment.
- Patch9: Move the 'dst_type' declaration to while() statement.
- Patch12: Add Philippe Mathieu-Daudé review comment.
- Patch13: Move the 'set' declaration to the for() statement.
v2->v3:
- Patch1: Add Kevin Wolf review comment.
- Patch2: Keep the 'flags' then use it(Base on Kevin's comments).
- Patch3: Add Kevin Wolf review comment.
- Patch9: Add Francisco Iglesias and Alistair Francis review comment.
- Patch10: Juan Quintela has added it to the queue and delete it.
- Patch12->Patch11: Add Philippe Mathieu-Daudé review comment.
- Patch13->Patch12: Add Philippe Mathieu-Daudé review comment.
v3->v4:
- Deleted the patches that have been merged in the v3.
- Modify "scsi/esp-pci" Patch, use g_assert with variable size.
Chen Qun (3):
scsi/esp-pci: Remove redundant statement in esp_pci_io_write() display/blizzard: Remove redundant statement in
blizzard_draw_line16_32()
timer/exynos4210_mct: Remove redundant statement in
exynos4210_mct_write()hw/display/blizzard.c | 1 - hw/scsi/esp-pci.c | 1 + hw/timer/exynos4210_mct.c | 4 ---- 3 files changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
2.23.0
PATCH v4 1/3 scsi/esp-pci: Remove redundant statement in esp_pci_io_write()
Clang static code analyzer show warning:
hw/scsi/esp-pci.c:198:9: warning: Value stored to 'size' is never read
size = 4;
^ ~---
Cc: Paolo Bonzini <[email protected]>
Cc:Fam Zheng <[email protected]>v1->v2:
keep ' size = 4' and add 'g_assert(size >= 4)' after if() statement. (Base on Laurent's comments)
--- hw/scsi/esp-pci.c | 1 + 1 file changed, 1 insertion(+)
hw/scsi/esp-pci.c +1 -0
@@ -197,6 +197,7 @@ static void esp_pci_io_write(void *opaque, hwaddr addr, addr &= ~3 ; size =4 ; } +g_assert (size >=4 );if (addr <0x40 ) {/* SCSI core reg */
Signature · 1 line
2.23.0
Re: [PATCH v4 1/3] scsi/esp-pci: Remove redundant statement in esp_pci_io_write()
Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 23 lines
Clang static code analyzer show warning:
hw/scsi/esp-pci.c:198:9: warning: Value stored to 'size' is never readsize = 4; ^ ~Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Paolo Bonzini <[email protected]>
Cc:Fam Zheng <[email protected]>v1->v2:
keep ' size = 4' and add 'g_assert(size >= 4)' afterif()statement. (Base on Laurent's comments)--- hw/scsi/esp-pci.c | 1 + 1 file changed, 1 insertion(+)hw/scsi/esp-pci.c +0
-0
hw/scsi/esp-pci.c static void esp_pci_io_write(void *opaque, hwaddr addr, · line 203
Quoted 7 lines
hw/scsi/esp-pci.c +1
-0@@ -197,6 +197,7 @@ static void esp_pci_io_write(void *opaque, hwaddr addr, addr &= ~3 ; size =4 ; } +g_assert (size >=4 );if (addr <0x40 ) {/* SCSI core reg */
PATCH v4 2/3 display/blizzard: Remove redundant statement in blizzard_draw_line16_32()
In reply to Chen QunClang static code analyzer show warning:
hw/display/blizzard.c:940:9: warning: Value stored to 'data' is never read
data >>= 5;
^ ~---
Cc: Andrzej Zaborowski <[email protected]>
Cc: Peter Maydell <[email protected]>
--- hw/display/blizzard.c | 1 - 1 file changed, 1 deletion(-)
hw/display/blizzard.c +0 -1
@@ -937,7 +937,6 @@ static void blizzard_draw_line16_32(uint32_t *dest, g = (data &0x3f ) <<2 ; data >>=6 ; r = (data &0x1f ) <<3 ; - data >>=5 ; *dest++ =rgb_to_pixel32 (r, g, b); } }
Signature · 1 line
2.23.0
Re: [PATCH v4 2/3] display/blizzard: Remove redundant statement in blizzard_draw_line16_32()
Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 19 lines
Clang static code analyzer show warning:
hw/display/blizzard.c:940:9: warning: Value stored to 'data' is never readdata >>= 5; ^ ~Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Andrzej Zaborowski <[email protected]>
Cc: Peter Maydell <[email protected]>--- hw/display/blizzard.c | 1 - 1 file changed, 1 deletion(-)hw/display/blizzard.c +0
-0
hw/display/blizzard.c static void blizzard_draw_line16_32(uint32_t *dest, · line 942
Quoted 7 lines
hw/display/blizzard.c +0
-1@@ -937,7 +937,6 @@ static void blizzard_draw_line16_32(uint32_t *dest, g = (data &0x3f ) <<2 ; data >>=6 ; r = (data &0x1f ) <<3 ; - data >>=5 ; *dest++ =rgb_to_pixel32 (r, g, b); } }
Perhaps it would be clearer to use extract32() to compute r, g and b?
Thanks,
Laurent
Re: [PATCH v4 2/3] display/blizzard: Remove redundant statement in blizzard_draw_line16_32()
Le 24/03/2020 à 09:38, Laurent Vivier a écrit :
Quoted 14 lines
Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 13 lines
Clang static code analyzer show warning:
hw/display/blizzard.c:940:9: warning: Value stored to 'data' is never readdata >>= 5; ^ ~Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Andrzej Zaborowski <[email protected]>
Cc: Peter Maydell <[email protected]>--- hw/display/blizzard.c | 1 - 1 file changed, 1 deletion(-)
Quoted 15 lines
hw/display/blizzard.c static void blizzard_draw_line16_32(uint32_t *dest, · line 942
Quoted 13 lines
hw/display/blizzard.c +0
-1@@ -937,7 +937,6 @@ static void blizzard_draw_line16_32(uint32_t *dest, g = (data &0x3f ) <<2 ; data >>=6 ; r = (data &0x1f ) <<3 ; - data >>=5 ; *dest++ =rgb_to_pixel32 (r, g, b); } }Perhaps it would be clearer to use
extract32()to compute r, g and b?
in fact extract16() as data is uint16_t...
Thanks,
Laurent
RE: [PATCH v4 2/3] display/blizzard: Remove redundant statement in blizzard_draw_line16_32()
Quoted 42 lines
-----Original Message-----
From: Laurent Vivier [mailto:[email protected]]
Sent: Tuesday, March 24, 2020 4:40 PM
To: Chenqun (kuhn) <[email protected]>; [email protected]; [email protected]
Cc: Zhanghailiang <[email protected]>; [email protected]; Euler Robot <[email protected]>; Andrzej Zaborowski <[email protected]>; Peter Maydell <[email protected]>
Subject: Re: [PATCH v4 2/3] display/blizzard: Remove redundant statement inblizzard_draw_line16_32()Le 24/03/2020 à 09:38, Laurent Vivier a écrit :
Quoted 14 lines
Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 13 lines
Clang static code analyzer show warning:
hw/display/blizzard.c:940:9: warning: Value stored to 'data' is never readdata >>= 5; ^ ~Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Andrzej Zaborowski <[email protected]>
Cc: Peter Maydell <[email protected]>--- hw/display/blizzard.c | 1 - 1 file changed, 1 deletion(-)Quoted 15 lines
hw/display/blizzard.c static void blizzard_draw_line16_32(uint32_t *dest, · line 942
Quoted 13 lines
hw/display/blizzard.c index renamed from hw/display/blizzard.c +0
-0
359e399c2a..62517bdf75100644hw/display/blizzard.c +0
-1@@ -937,7 +937,6 @@ static void blizzard_draw_line16_32(uint32_t *dest, g = (data &0x3f ) <<2 ; data >>=6 ; r = (data &0x1f ) <<3 ; - data >>=5 ; *dest++ =rgb_to_pixel32 (r, g, b); } }Perhaps it would be clearer to use
extract32()to compute r, g and b?
Quoted 1 line
in fact
extract16()as data isuint16_t...
Good Point, I will update it next verison.
Thanks.
PATCH v4 3/3 timer/exynos4210_mct: Remove redundant statement in exynos4210_mct_write()
In reply to Chen QunClang static code analyzer show warning: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);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~---
Cc: Igor Mitsyanko <[email protected]>
Cc: Peter Maydell <[email protected]>
--- hw/timer/exynos4210_mct.c | 4 ---- 1 file changed, 4 deletions(-)
hw/timer/exynos4210_mct.c +0 -4
@@ -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,8 +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); s->l_timer[lt_i].reg.wstat |=L_WSTAT_FRCCNTB_WRITE ;
Signature · 1 line
2.23.0
Re: [PATCH v4 3/3] timer/exynos4210_mct: Remove redundant statement in exynos4210_mct_write()
Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 10 lines
Clang static code analyzer show warning:
hw/timer/exynos4210_mct.c:1370:9: warning: Value stored to 'index' is never readindex = 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); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It would be interesting to understand why we need the index for these registers in exynos4210_mct_read() and not in exynos4210_mct_write().
Thanks,
Laurent
Quoted 39 lines
Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Igor Mitsyanko <[email protected]>
Cc: Peter Maydell <[email protected]>--- hw/timer/exynos4210_mct.c | 4 ---- 1 file changed, 4 deletions(-)hw/timer/exynos4210_mct.c +0
-4@@ -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,8 +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); s->l_timer[lt_i].reg.wstat |=L_WSTAT_FRCCNTB_WRITE ;
RE: [PATCH v4 3/3] timer/exynos4210_mct: Remove redundant statement in exynos4210_mct_write()
Quoted 22 lines
-----Original Message-----
From: Laurent Vivier [mailto:[email protected]]
Sent: Tuesday, March 24, 2020 6:59 PM
To: Chenqun (kuhn) <[email protected]>; [email protected]; [email protected]
Cc: Zhanghailiang <[email protected]>; [email protected]; Euler Robot <[email protected]>; Igor Mitsyanko <[email protected]>; Peter Maydell <[email protected]>
Subject: Re: [PATCH v4 3/3] timer/exynos4210_mct: Remove redundant statement inexynos4210_mct_write()Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 2 lines
Clang static code analyzer show warning:
hw/timer/exynos4210_mct.c:1370:9: warning: Value stored to 'index' is neverread
Quoted 3 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/timer/exynos4210_mct.c:1399:9: warning: Value stored to 'index' is neverread
Quoted 3 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/timer/exynos4210_mct.c:1441:9: warning: Value stored to 'index' is never
Quoted 7 lines
read
Quoted 2 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~It would be interesting to understand why we need the index for these registers in
exynos4210_mct_read()and not inexynos4210_mct_write().
I think the index can also be used in exynos4210_mct_write(), but the original author used a more obvious reg name instead of it.
The obvious reg name:
case L0_TCNTB: case L1_TCNTB:
reg name is : L_REG_CNT_TCNTB
case L0_ICNTB: case L1_ICNTB:
reg name is : L_REG_CNT_ICNTB
case L0_FRCNTB: case L1_FRCNTB:
reg name is : L_REG_CNT_FRCCNTB
Thanks.
Quoted 43 lines
Quoted 43 lines
Reported-by Euler Robot <[email protected]>Signed-off-by Chen Qun <[email protected]>---
Cc: Igor Mitsyanko <[email protected]>
Cc: Peter Maydell <[email protected]>--- hw/timer/exynos4210_mct.c | 4 ---- 1 file changed, 4 deletions(-)hw/timer/exynos4210_mct.c +0
-1@@ -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.
hw/timer/exynos4210_mct.c +0
-1@@ -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,8 +1436,6 @@ static void exynos4210_mct_write(void *opaque, hwaddr offset,
case
L0_FRCNTB: caseL1_FRCNTB:
lt_i=GET_L_TIMER_IDX(offset);hw/timer/exynos4210_mct.c +0
-2- index =GET_L_TIMER_CNT_REG_IDX (offset, lt_i); -DPRINTF ("local timer[%d] FRCNTB write %llx\n" , lt_i, value); s->l_timer[lt_i].reg.wstat |=L_WSTAT_FRCCNTB_WRITE ;
Laurent Vivier
Reviewed-byRe: [PATCH v4 3/3] timer/exynos4210_mct: Remove redundant statement in exynos4210_mct_write()
Le 24/03/2020 à 13:22, Chenqun (kuhn) a écrit :
Quoted 35 lines
Quoted 22 lines
-----Original Message-----
From: Laurent Vivier [mailto:[email protected]]
Sent: Tuesday, March 24, 2020 6:59 PM
To: Chenqun (kuhn) <[email protected]>; [email protected]; [email protected]
Cc: Zhanghailiang <[email protected]>; [email protected]; Euler Robot <[email protected]>; Igor Mitsyanko <[email protected]>; Peter Maydell <[email protected]>
Subject: Re: [PATCH v4 3/3] timer/exynos4210_mct: Remove redundant statement inexynos4210_mct_write()Le 24/03/2020 à 09:22, Chen Qun a écrit :
Quoted 2 lines
Clang static code analyzer show warning:
hw/timer/exynos4210_mct.c:1370:9: warning: Value stored to 'index' is neverread
Quoted 3 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/timer/exynos4210_mct.c:1399:9: warning: Value stored to 'index' is neverread
Quoted 3 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/timer/exynos4210_mct.c:1441:9: warning: Value stored to 'index' is neverQuoted 7 lines
read
Quoted 2 lines
index = GET_L_TIMER_CNT_REG_IDX(offset, lt_i); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~It would be interesting to understand why we need the index for these registers in
exynos4210_mct_read()and not inexynos4210_mct_write().I think the index can also be used in
exynos4210_mct_write(), but the original author used a more obvious reg name instead of it.The obvious reg name:
caseL0_TCNTB: caseL1_TCNTB:
reg name is :L_REG_CNT_TCNTB
Quoted 6 lines
case
L0_ICNTB: caseL1_ICNTB:
reg name is :L_REG_CNT_ICNTBcase
L0_FRCNTB: caseL1_FRCNTB:
reg name is :L_REG_CNT_FRCCNTB
Yes, you're right.
Computed index gives the value used with s->l_timer[lt_i].reg.cnt[].
Thanks,
Laurent