Skip to contentSkip to conversation

hw/pxa2xx.c: Fix handling of R/WC bits in PMCR

PATCH Applied Peter Maydell 3 participants 4 messages Nov 9, 2011 – Nov 11, 2011

lore
Share & tools
lore
#0 lore raw

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
index bfc28a9..d38b922 100644
@@ -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
#1 lore raw
Quoted 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).

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 19 lines
---
  hw/pxa2xx.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
hw/pxa2xx.c +3 -1
index bfc28a9..d38b922 100644
@@ -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;
 
#2 lore raw

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).

Applied.  Thanks.

Regards,

Anthony Liguori

Quoted 11 lines

---
 hw/pxa2xx.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
hw/pxa2xx.c +0 -0
index bfc28a9..d38b922 100644
@@ -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 -0
      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;

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

#3 lore raw
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) & 0x2a instead, 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