Skip to contentSkip to conversation

usb-ohci: td.cbp incorrectly updated near page end

Qemu-devel Andriy Gapon 3 participants 3 messages Dec 22, 2011 – Jan 6, 2012

lore
Share & tools
lore
#0 lore raw

The current code that updates the cbp value after a transfer looks like this:
td.cbp += ret;
if ((td.cbp & 0xfff) + ret > 0xfff) {
<handle page overflow>
because the 'ret' value is effectively added twice the check may fire too early when the overflow hasn't happened yet.

Below is one of the possible changes that correct the behavior:

usb-ohci.c renamed from usb-ohci.c.orig +3 -3
@@ -1025,10 +1031,10 @@ static int ohci_service_td(OHCIState *oh
         if (ret == len) {
             td.cbp = 0;
         } else {
-            td.cbp += ret;
             if ((td.cbp & 0xfff) + ret > 0xfff) {
-                td.cbp &= 0xfff;
-                td.cbp |= td.be & ~0xfff;
+                td.cbp = (td.be & ~0xfff) + ((td.cbp + ret) & 0xfff);
+            } else {
+                td.cbp += ret;
             }
         }
         td.flags |= OHCI_TD_T1;
Signature · 1 line
Andriy Gapon
Reviewed-by
#1 lore raw
Quoted 7 lines · Andriy Gapon

The current code that updates the cbp value after a transfer looks like this:
td.cbp += ret;
if ((td.cbp & 0xfff) + ret > 0xfff) {
<handle page overflow>
because the 'ret' value is effectively added twice the check may fire too early when the overflow hasn't happened yet.

#2 lore raw
In reply to Andriy Gapon
Quoted 6 lines · Andriy Gapon

The current code that updates the cbp value after a transfer looks like this:
td.cbp += ret;
if ((td.cbp & 0xfff) + ret > 0xfff) {
<handle page overflow>
because the 'ret' value is effectively added twice the check may fire too early when the overflow hasn't happened yet.

Patch added to usb patch queue.

thanks,
Gerd