From patchwork Tue Jun 8 13:12:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 54971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 567E5B7D5B for ; Tue, 8 Jun 2010 23:18:34 +1000 (EST) Received: from localhost ([127.0.0.1]:33373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLyhL-0007k6-HX for incoming@patchwork.ozlabs.org; Tue, 08 Jun 2010 09:18:31 -0400 Received: from [140.186.70.92] (port=33639 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLybk-0006Fb-72 for qemu-devel@nongnu.org; Tue, 08 Jun 2010 09:12:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLybU-0001wy-I1 for qemu-devel@nongnu.org; Tue, 08 Jun 2010 09:12:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15814) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLybU-0001wm-6i for qemu-devel@nongnu.org; Tue, 08 Jun 2010 09:12:28 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o58DCQP4018921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Jun 2010 09:12:26 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o58DCLhK004177; Tue, 8 Jun 2010 09:12:24 -0400 From: Jes.Sorensen@redhat.com To: anthony@codemonkey.ws Date: Tue, 8 Jun 2010 15:12:18 +0200 Message-Id: <1276002738-821-2-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1276002738-821-1-git-send-email-Jes.Sorensen@redhat.com> References: <1276002738-821-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, shavivi@redhat.com, qemu-devel@nongnu.org, Jes Sorensen Subject: [Qemu-devel] [PATCH] un-register kbd driver in case of USB kbd unplug. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 | 8 ++++++-- input.c | 6 ++++++ 3 files changed, 13 insertions(+), 2 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..ca04511 100644 --- a/hw/usb-hid.c +++ b/hw/usb-hid.c @@ -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) 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;