un-register kbd driver for USB kbd unplug
PATCH v2 1/1 un-register kbd driver for USB kbd unplug
From: Jes Sorensen <[email protected]>
Hi,
Kevin pointed out the TODO comment was obsolete and also suggested turning the if lines into a switch statement. It seems cleaner, so here is a second version of the patch.
This is a fairly simple fix for the problem where the keyboard event handler is left in place when a keyboard is unplugged, eg. USB.
The long term solution would be to use Shahar Havivi's multi-keyboard support patch[1] from March, but until Shahar's patch is ready, this one fixes the current crash problem.
Cheers,
Jes
[1]: http://www.mail-archive.com/[email protected]/msg28589.html
Jes Sorensen (1):
un-register kbd driver in case of USB kbd unplug.
console.h | 1 + hw/usb-hid.c | 8 ++++++-- input.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)
PATCH 1/1 un-register kbd driver in case of USB kbd unplug.
From: Jes Sorensen <[email protected]>
If a USB keyboard is unplugged, the keyboard eventhandler is never removed, and events will continue to be passed through to the device, causing crashes or memory corruption.
--- console.h | 1 + hw/usb-hid.c | 8 ++++++-- input.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)
console.h +1 -0
@@ -42,6 +42,7 @@ typedef struct QEMUPutLEDEntry { } QEMUPutLEDEntry;void qemu_add_kbd_event_handler (QEMUPutKBDEvent *func,void *opaque); +void qemu_remove_kbd_event_handler (void );QEMUPutMouseEntry *qemu_add_mouse_event_handler (QEMUPutMouseEvent *func,void *opaque,int absolute,const char *name);
hw/usb-hid.c +6 -2
@@ -854,9 +854,13 @@ static void usb_hid_handle_destroy(USBDevice *dev) {USBHIDState *s = (USBHIDState *)dev; -if (s->kind !=USB_KEYBOARD ) +switch (s->kind) { +case USB_KEYBOARD : +qemu_remove_kbd_event_handler (); +break ; +default :qemu_remove_mouse_event_handler (s->ptr.eh_entry); -/* TODO: else */ + } }static int usb_hid_initfn (USBDevice *dev,int kind)
input.c +6 -0
@@ -42,6 +42,12 @@ void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) qemu_put_kbd_event = func; } +void qemu_remove_kbd_event_handler (void ) +{ + qemu_put_kbd_event_opaque =NULL ; + qemu_put_kbd_event =NULL ; +} +static void check_mode_change (void ) {static int current_is_absolute, current_has_absolute;
Signature · 1 line
1.6.5.2
Re: [Qemu-devel] [PATCH] un-register kbd driver in case of USB kbd unplug.
Quoted 5 lines · [email protected] writes:
From: Jes Sorensen <[email protected]>
If a USB keyboard is unplugged, the keyboard eventhandler is never removed, and events will continue to be passed through to the device, causing crashes or memory corruption.
Looks good.
I wonder how many more unplug surprises to expect.
Anthony Liguori
AppliedRe: [Qemu-devel] [PATCH] un-register kbd driver in case of USB kbd unplug.
In reply to [email protected]Quoted 8 lines · On 06/08/2010 08:12 AM, [email protected] wrote:
From: Jes Sorensen<[email protected]>
If a USB keyboard is unplugged, the keyboard eventhandler is never removed, and events will continue to be passed through to the device, causing crashes or memory corruption.
Signed-off-by Jes Sorensen<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 56 lines
--- console.h | 1 + hw/usb-hid.c | 8 ++++++-- input.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-)console.h +1
-0@@ -42,6 +42,7 @@ typedef struct QEMUPutLEDEntry { } QEMUPutLEDEntry;void qemu_add_kbd_event_handler (QEMUPutKBDEvent *func,void *opaque); +void qemu_remove_kbd_event_handler (void );QEMUPutMouseEntry *qemu_add_mouse_event_handler (QEMUPutMouseEvent *func,void *opaque,int absolute,const char *name);hw/usb-hid.c +6
-2@@ -854,9 +854,13 @@ static void usb_hid_handle_destroy(USBDevice *dev) {USBHIDState *s = (USBHIDState *)dev; -if (s->kind !=USB_KEYBOARD ) +switch (s->kind) { +case USB_KEYBOARD : +qemu_remove_kbd_event_handler (); +break ; +default :qemu_remove_mouse_event_handler (s->ptr.eh_entry); -/* TODO: else */ + } }static int usb_hid_initfn (USBDevice *dev,int kind)input.c +6
-0@@ -42,6 +42,12 @@ void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque) qemu_put_kbd_event = func; } +void qemu_remove_kbd_event_handler (void ) +{ + qemu_put_kbd_event_opaque =NULL ; + qemu_put_kbd_event =NULL ; +} +static void check_mode_change (void ) {static int current_is_absolute, current_has_absolute;