hw/pxa2xx.c: Fix handling of R/WC bits in PMCR
PATCH 1/1 hw/pxa2xx.c: Fix handling of R/WC bits in PMCR
Fix a bug in handling the write-one-to-clear bits in the PMCR which meant that we would always clear the bit even if the value written was a zero. Spotted by Coverity (see bug 887883).
--- hw/pxa2xx.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/pxa2xx.c +3 -1
@@ -114,7 +114,9 @@ static void pxa2xx_pm_write(void *opaque, target_phys_addr_t addr,switch (addr) {case PMCR : - s->pm_regs[addr >>2 ] &=0x15 & ~(value &0x2a ); +/* Clear the write-one-to-clear bits... */ + s->pm_regs[addr >>2 ] &= ~(value &0x2a ); +/* ...and set the plain r/w bits */ s->pm_regs[addr >>2 ] |= value &0x15 ;break ;
Signature · 1 line
1.7.1
Anthony Liguori
AppliedQuoted 5 lines · Peter Maydell
Fix a bug in handling the write-one-to-clear bits in the PMCR which meant that we would always clear the bit even if the value written was a zero. Spotted by Coverity (see bug 887883).
Signed-off-by Peter Maydell<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 19 lines
--- hw/pxa2xx.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)hw/pxa2xx.c +3
-1@@ -114,7 +114,9 @@ static void pxa2xx_pm_write(void *opaque, target_phys_addr_t addr,switch (addr) {case PMCR : - s->pm_regs[addr>>2 ]&=0x15 & ~(value&0x2a ); +/* Clear the write-one-to-clear bits... */ + s->pm_regs[addr>>2 ]&= ~(value&0x2a ); +/* ...and set the plain r/w bits */ s->pm_regs[addr>>2 ] |= value&0x15 ;break ;
Hi,
Quoted 25 lines · Anthony Liguori
Quoted 6 lines · Peter Maydell
Fix a bug in handling the write-one-to-clear bits in the PMCR which meant that we would always clear the bit even if the value written was a zero. Spotted by Coverity (see bug 887883).
Signed-off-by Peter Maydell<[email protected]>Applied. Thanks.
Regards,
Anthony Liguori
Quoted 11 lines
---
hw/pxa2xx.c | 4 +++-1 files changed, 3 insertions(+), 1 deletions(-)hw/pxa2xx.c +0
-0@@ -114,7 +114,9 @@ static void pxa2xx_pm_write(void *opaque, target_phys_addr_t addr,
Quoted 7 lines
Quoted 7 lines
hw/pxa2xx.c +0
-0switch (addr) {case PMCR:
- s->pm_regs[addr>> 2]&= 0x15& ~(value& 0x2a);
+ /* Clear the write-one-to-clear bits... */
+ s->pm_regs[addr>> 2]&= ~(value& 0x2a);
+ /* ...and set the plain r/w bits */ s->pm_regs[addr>> 2] |= value& 0x15;
As I was about to push these patches also, I noticed this isn't exactly setting the r/w bits. But it would work if the first line was (~value) & 0x2a instead, should I fix it this way, am I looking at it right?
Cheers
Quoted 10 lines · andrzej zaborowski
Quoted 5 lines
Quoted 5 lines
- s->pm_regs[addr>> 2]&= 0x15& ~(value& 0x2a);
+ /* Clear the write-one-to-clear bits... */
+ s->pm_regs[addr>> 2]&= ~(value& 0x2a);
+ /* ...and set the plain r/w bits */ s->pm_regs[addr>> 2] |= value& 0x15;As I was about to push these patches also, I noticed this isn't exactly setting the r/w bits. But it would work if the first line was (~value) &
0x2ainstead, should I fix it this way, am I looking at it right?
Rats, you're right. Your fix works (although it renders the comment wrong as it's then not just clearing the W1C bits). Alternatively add an extra line to give:
/* Clear the write-one-to-clear bits... */
s->pm_regs[addr >> 2] &= ~(value & 0x2a);
/* ...and set the plain r/w bits */
s->pm_regs[addr >> 2] &= ~0x15;
s->pm_regs[addr>> 2] |= value & 0x15;(this is slightly different in effect from your code in that it leaves register bits [31:5] untouched where yours will always clear them.) Feel free to do whichever you think is clearest.
-- PMM