]> xenbits.xensource.com Git - qemu-xen-3.3-testing.git/commitdiff
fix usb-hid emulation SET_IDLE
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 7 Jan 2009 15:16:04 +0000 (15:16 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 12 Feb 2009 11:15:32 +0000 (11:15 +0000)
there is a bug in the current usb-hid emulation code that affects the
way the idle flag is handled: the spec clearly states that when SET_IDLE
is called with a value == 0 means "do not send any event unless there is
an actual change". However we are currently assuming the opposite
meaning of the flag.
This patch fixes it and it also fixes a possible initialization issue
that is uncovered by using the default idle flag set to 0.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
[supplied patch also trivially changed by Ian Jackson]
(cherry picked from commit 144cb9b13bb57d40b69a5100ab4dd91d9f0036e0)

hw/usb-hid.c

index 6aa26f9b074114424b299d3a4dacd6e4e3708a03..4dad6f5d0ae49074db297acb7c4c6669fb73be8f 100644 (file)
@@ -525,8 +525,7 @@ static inline int int_clamp(int val, int vmin, int vmax)
 
 static int usb_suppress_report(USBHIDState *hs, int unchanged) {
     /* TODO: Implement finite idle delays.  */
-    if (!hs->idle) return 0; /* SET_IDLE 0 means always report */
-    return unchanged;
+    return !hs->idle && unchanged; /* SET_IDLE 0 means do not report */
 }
 
 static int usb_pointer_poll(USBHIDState *hs, uint8_t *buf, int len)
@@ -535,15 +534,15 @@ static int usb_pointer_poll(USBHIDState *hs, uint8_t *buf, int len)
     USBPointerState *s = &hs->ptr;
     USBPointerEvent *e;
 
-    if (usb_suppress_report(hs, s->head == s->tail))
-       return USB_RET_NAK;
-
     if (!s->mouse_grabbed) {
        s->eh_entry = qemu_add_mouse_event_handler(usb_pointer_event, hs,
                                           !s->xyrel, "QEMU USB Pointer");
        s->mouse_grabbed = 1;
     }
 
+    if (usb_suppress_report(hs, s->head == s->tail))
+       return USB_RET_NAK;
+
     if (s->head == s->tail)
         /* use the last report */
         s->head = (s->head - 1) & QUEUEINDEXMASK;