From patchwork Wed Oct 31 11:54:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 195855 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 319D12C0082 for ; Wed, 31 Oct 2012 22:53:22 +1100 (EST) Received: from localhost ([::1]:36433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTWrH-0004PV-Cc for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 07:53:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTWqu-0004En-VD for qemu-devel@nongnu.org; Wed, 31 Oct 2012 07:53:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTWqt-0005Sc-Ul for qemu-devel@nongnu.org; Wed, 31 Oct 2012 07:52:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45699) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTWqt-0005SW-Lz for qemu-devel@nongnu.org; Wed, 31 Oct 2012 07:52:55 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9VBqsdR001662 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 31 Oct 2012 07:52:54 -0400 Received: from shalem.localdomain.com (vpn1-6-145.ams2.redhat.com [10.36.6.145]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9VBqnwe009534; Wed, 31 Oct 2012 07:52:53 -0400 From: Hans de Goede To: Gerd Hoffmann Date: Wed, 31 Oct 2012 12:54:37 +0100 Message-Id: <1351684477-12213-3-git-send-email-hdegoede@redhat.com> In-Reply-To: <1351684477-12213-1-git-send-email-hdegoede@redhat.com> References: <1351684477-12213-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/2] uhci: Don't crash on device disconnect X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org My recent uhci cleanup series has introduced a regression, where qemu sometimes crashes on a device disconnect. The problem is that the uhci code never checked for a device not / no longer existing, instead it was relying on usb_handle_packet accepting a NULL device. But since we now pass usb_handle_packet q->ep->dev, rather then just a local dev variable, we crash as q->ep == NULL due to the device no longer existing. This patch fixes this. Note that this patch also improves over the old behavior were we would: 1) create a queue for the device 2) create an async for the packet 3) have usb_handle_packet fail 4) destroy the async 5) wait for the queue to be idle for 32 frames 6) destroy the queue Which was rather sub-optimal. Signed-off-by: Hans de Goede --- hw/usb/hcd-uhci.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index 99ed063..1ef1db9 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -879,6 +879,11 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr, if (q == NULL) { USBDevice *dev = uhci_find_device(s, (td->token >> 8) & 0x7f); USBEndpoint *ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); + + if (ep == NULL) { + return uhci_handle_td_error(s, td, td_addr, USB_RET_NODEV, + int_mask); + } q = uhci_queue_new(s, qh_addr, td, ep); } async = uhci_async_alloc(q, td_addr);