hw/misc/iotkit-secctl: Fix writing to 'PPC Interrupt Clear' register
PATCH 1/1 hw/misc/iotkit-secctl: Fix writing to 'PPC Interrupt Clear' register
Fix warning reported by Clang static code analyzer:
CC hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never read
value &= 0x00f000f3;
^ ~~~~~~~~~~--- hw/misc/iotkit-secctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/iotkit-secctl.c +1 -1
@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,qemu_set_irq (s->sec_resp_cfg, s->secrespcfg);break ;case A_SECPPCINTCLR : - value &=0x00f000f3 ; + s->secppcintstat = ~value &0x00f000f3 ;foreach_ppc (s, iotkit_secctl_ppc_update_irq_clear);break ;case A_SECPPCINTEN :
Signature · 1 line
2.21.1
Quoted 20 lines · Philippe Mathieu-Daudé
Fix warning reported by Clang static code analyzer:
CC
hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never readvalue &= 0x00f000f3; ^ ~~~~~~~~~~Fixes b3717c23e1cReported-by Clang Static AnalyzerSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/misc/iotkit-secctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/misc/iotkit-secctl.c +0
-0
hw/misc/iotkit-secctl.c static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, · line 343
Quoted 5 lines
hw/misc/iotkit-secctl.c +1
-1@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,qemu_set_irq (s->sec_resp_cfg, s->secrespcfg);break ;case A_SECPPCINTCLR : - value &=0x00f000f3 ; + s->secppcintstat = ~value &0x00f000f3 ;
This is (obviously) a bug, but I don't think your fix is right. This register has bits which are write-one-to-clear, (plus some other bits that are reserved and RAZ/WI) so we want:
s->secppcintstat &= ~(value & 0x00f000f3);
(In particular bitwise-not has higher precedence than bitwise-and, so your expression will end up writing zero to s->specppcintstat for any valid guest write.)
My guess is that when I originally wrote the code I meant to write something like
value &= 0x00f000f3;
s->secppcintstat &= ~value;
and forgot the second line.
thanks
-- PMM
Quoted 34 lines · Peter Maydell
Quoted 20 lines · Philippe Mathieu-Daudé
Fix warning reported by Clang static code analyzer:
CC
hw/misc/iotkit-secctl.o
hw/misc/iotkit-secctl.c:343:9: warning: Value stored to 'value' is never readvalue &= 0x00f000f3; ^ ~~~~~~~~~~Fixes b3717c23e1cReported-by Clang Static AnalyzerSigned-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/misc/iotkit-secctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/misc/iotkit-secctl.c +0
-0hw/misc/iotkit-secctl.c static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr, · line 343
Quoted 5 lines
hw/misc/iotkit-secctl.c +1
-1@@ -340,7 +340,7 @@ static MemTxResult iotkit_secctl_s_write(void *opaque, hwaddr addr,qemu_set_irq (s->sec_resp_cfg, s->secrespcfg);break ;case A_SECPPCINTCLR : - value &=0x00f000f3 ; + s->secppcintstat = ~value &0x00f000f3 ;This is (obviously) a bug, but I don't think your fix is right. This register has bits which are write-one-to-clear, (plus some other bits that are reserved and RAZ/WI) so we want:
s->secppcintstat&= ~(value &0x00f000f3);
Quoted 3 lines
(In particular bitwise-not has higher precedence than bitwise-and, so your expression will end up writing zero to
s->specppcintstatfor any valid guest write.)
Oops indeed :)
Quoted 8 lines
My guess is that when I originally wrote the code I meant to write something like
value &= 0x00f000f3; s->secppcintstat &= ~value;and forgot the second line.
thanks
-- PMM