Skip to contentSkip to conversation

rtl8139: fix regression in TxStatus/TxAddr read

PATCH Applied Avi Kivity 2 participants 2 messages May 7, 2012

lore
Share & tools
lore

Avi Kivity

author
#0 lore raw

PATCH 1/1 rtl8139: fix regression in TxStatus/TxAddr read

Commit afe0a595356192 added byte reads for TxStatus/TxAddr, but broke 32-bit reads; the mask generation

(1 << (8 * size)) - 1

is unspecified in C for size >= sizeof(int), and in fact returns 0 on x86.

Fix by using a larger type.

Fixes (at least) Fedora 9 i386 with -machine kernel_irqchip=on. I didn't see it with the qemu APIC implementation; may be due to timing or (more likely) a tester error.

---
 hw/rtl8139.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rtl8139.c +1 -1
index 4d0f5ba..eb22d04 100644
@@ -2500,7 +2500,7 @@ static uint32_t rtl8139_TxStatus_TxAddr_read(RTL8139State *s, uint32_t regs[],
     case 1: /* fall through */
     case 2: /* fall through */
     case 4:
-        ret = (regs[reg] >> offset * 8) & ((1 << (size * 8)) - 1);
+        ret = (regs[reg] >> offset * 8) & (((uint64_t)1 << (size * 8)) - 1);
         DPRINTF("TxStatus/TxAddr[%d] read addr=0x%x size=0x%x val=0x%08x\n",
                 reg, addr, size, ret);
         break;
Signature · 1 line
1.7.10.1
#1 lore raw
Quoted 8 lines · Avi Kivity

Commit afe0a595356192 added byte reads for TxStatus/TxAddr, but broke 32-bit reads; the mask generation

   (1 << (8 * size)) - 1

is unspecified in C for size >= sizeof(int), and in fact returns 0 on x86.

Quoted 7 lines

Fix by using a larger type.

Fixes (at least) Fedora 9 i386 with -machine kernel_irqchip=on. I didn't see it with the qemu APIC implementation; may be due to timing or (more likely) a tester error.

Applied, thanks

Quoted 19 lines
---
 hw/rtl8139.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/rtl8139.c +1 -1
index 4d0f5ba..eb22d04 100644
@@ -2500,7 +2500,7 @@ static uint32_t rtl8139_TxStatus_TxAddr_read(RTL8139State *s, uint32_t regs[],
     case 1: /* fall through */
     case 2: /* fall through */
     case 4:
-        ret = (regs[reg] >> offset * 8) & ((1 << (size * 8)) - 1);
+        ret = (regs[reg] >> offset * 8) & (((uint64_t)1 << (size * 8)) - 1);
         DPRINTF("TxStatus/TxAddr[%d] read addr=0x%x size=0x%x val=0x%08x\n",
                 reg, addr, size, ret);
         break;
Signature · 1 line
1.7.10.1