Skip to contentSkip to conversation

hw/intc/arm_gicv3: fix an extra left-shift when reading IPRIORITYR

PATCH Applied Amol Surati 2 participants 2 messages Jun 14, 2018 – Jun 15, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/intc/arm_gicv3: fix an extra left-shift when reading IPRIORITYR

When either GICD_IPRIORITYR or GICR_IPRIORITYR is read as a 32-bit register, the post left-shift operator in the for loop causes an extra shift after the least significant byte has been placed.

The 32-bit value actually returned is therefore the expected value shifted left by 8 bits.

---
 hw/intc/arm_gicv3_dist.c   | 3 ++-
 hw/intc/arm_gicv3_redist.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/intc/arm_gicv3_dist.c +2 -1
index 93fe936862..53c55c5729 100644
@@ -441,7 +441,8 @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset,
         int i, irq = offset - GICD_IPRIORITYR;
         uint32_t value = 0;
 
-        for (i = irq + 3; i >= irq; i--, value <<= 8) {
+        for (i = irq + 3; i >= irq; i--) {
+            value <<= 8;
             value |= gicd_read_ipriorityr(s, attrs, i);
         }
         *data = value;
hw/intc/arm_gicv3_redist.c +2 -1
index 8a8684d76e..3b0ba6de1a 100644
@@ -192,7 +192,8 @@ static MemTxResult gicr_readl(GICv3CPUState *cs, hwaddr offset,
         int i, irq = offset - GICR_IPRIORITYR;
         uint32_t value = 0;
 
-        for (i = irq + 3; i >= irq; i--, value <<= 8) {
+        for (i = irq + 3; i >= irq; i--) {
+            value <<= 8;
             value |= gicr_read_ipriorityr(cs, attrs, i);
         }
         *data = value;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 8 lines · Amol Surati

When either GICD_IPRIORITYR or GICR_IPRIORITYR is read as a 32-bit register, the post left-shift operator in the for loop causes an extra shift after the least significant byte has been placed.

The 32-bit value actually returned is therefore the expected value shifted left by 8 bits.

Oops; thanks for the bugfix.

Applied to target-arm.next, thanks.

-- PMM