From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=39480 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLwI5-0002NE-QL for qemu-devel@nongnu.org; Tue, 08 Jun 2010 06:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLwI0-0008JM-Uz for qemu-devel@nongnu.org; Tue, 08 Jun 2010 06:44:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13694) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLwI0-0008JH-N1 for qemu-devel@nongnu.org; Tue, 08 Jun 2010 06:44:12 -0400 From: Jes.Sorensen@redhat.com Date: Tue, 8 Jun 2010 12:43:51 +0200 Message-Id: <1275993831-31425-2-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1275993831-31425-1-git-send-email-Jes.Sorensen@redhat.com> References: <1275993831-31425-1-git-send-email-Jes.Sorensen@redhat.com> Subject: [Qemu-devel] [PATCH] un-register kbd driver in case of USB kbd unplug. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: shavivi@redhat.com, qemu-devel@nongnu.org, Jes Sorensen From: Jes Sorensen 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 --- console.h | 1 + hw/usb-hid.c | 3 +++ input.c | 6 ++++++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/console.h b/console.h index cac959f..aafb031 100644 --- a/console.h +++ b/console.h @@ -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); diff --git a/hw/usb-hid.c b/hw/usb-hid.c index 8e6c6e0..333b626 100644 --- a/hw/usb-hid.c +++ b/hw/usb-hid.c @@ -856,6 +856,9 @@ static void usb_hid_handle_destroy(USBDevice *dev) if (s->kind != USB_KEYBOARD) qemu_remove_mouse_event_handler(s->ptr.eh_entry); + if (s->kind == USB_KEYBOARD) + qemu_remove_kbd_event_handler(); + /* TODO: else */ } diff --git a/input.c b/input.c index 651442d..ec05548 100644 --- a/input.c +++ b/input.c @@ -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; -- 1.6.5.2