From patchwork Thu Nov 1 15:54:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 196311 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 172C72C0348 for ; Fri, 2 Nov 2012 04:50:37 +1100 (EST) Received: from localhost ([::1]:53745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTx8G-0007Kr-Jd for incoming@patchwork.ozlabs.org; Thu, 01 Nov 2012 11:56:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTx6a-0004C4-UB for qemu-devel@nongnu.org; Thu, 01 Nov 2012 11:54:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTx6Y-0008BI-KD for qemu-devel@nongnu.org; Thu, 01 Nov 2012 11:54:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15049) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTx6Y-000886-0V for qemu-devel@nongnu.org; Thu, 01 Nov 2012 11:54:50 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qA1FsnNS013652 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 1 Nov 2012 11:54:49 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-42.ams2.redhat.com [10.36.116.42]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qA1FskDX000580; Thu, 1 Nov 2012 11:54:48 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id CE6AD45FF4; Thu, 1 Nov 2012 16:54:45 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 1 Nov 2012 16:54:36 +0100 Message-Id: <1351785284-15384-24-git-send-email-kraxel@redhat.com> In-Reply-To: <1351785284-15384-1-git-send-email-kraxel@redhat.com> References: <1351785284-15384-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Hans de Goede , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 23/31] 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 From: Hans de Goede 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 Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-uhci.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index a06372b..f4b555a 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -896,6 +896,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);