From patchwork Mon Sep 23 18:54:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 277289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A43E22C011F for ; Tue, 24 Sep 2013 04:54:56 +1000 (EST) Received: from localhost ([::1]:42059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOBHX-0005uO-TQ for incoming@patchwork.ozlabs.org; Mon, 23 Sep 2013 14:54:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOBH0-0005sQ-CT for qemu-devel@nongnu.org; Mon, 23 Sep 2013 14:54:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOBGu-0002HS-Dl for qemu-devel@nongnu.org; Mon, 23 Sep 2013 14:54:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOBGu-0002HN-4Z for qemu-devel@nongnu.org; Mon, 23 Sep 2013 14:54:12 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8NIsBoQ006265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Sep 2013 14:54:11 -0400 Received: from shalem.localdomain.com (vpn1-6-173.ams2.redhat.com [10.36.6.173]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8NIs8S0004792; Mon, 23 Sep 2013 14:54:10 -0400 From: Hans de Goede To: Gerd Hoffmann Date: Mon, 23 Sep 2013 20:54:01 +0200 Message-Id: <1379962447-5431-2-git-send-email-hdegoede@redhat.com> In-Reply-To: <1379962447-5431-1-git-send-email-hdegoede@redhat.com> References: <1379962447-5431-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 1/7] usb-host-libusb: Fix reset handling 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 The guest will issue an initial device reset when the device is attached, but since the current usb-host-libusb code only actually does the reset when udev->configuration != 0, and on attach the device is not yet configured, the reset gets ignored. This means that the device gets passed to the guest in an unknown state, which is not good. The udev->configuration check is there because of the release / claim interfaces done around the libusb_device_reset call, but these are not necessary. If interfaces are claimed when libusb_device_reset gets called libusb will release + reclaim them itself. The usb_host_ep_update call also is not necessary. If the reset succeeds the original config and interface alt settings will be restored. Last if the reset fails, that means the device has either disconnected or morphed into an another device and has been completely re-enumerated, so it is treated by the host as a new device and our handle is invalid, so on reset failure we need to call usb_host_nodev(). Signed-off-by: Hans de Goede --- hw/usb/host-libusb.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index b27f559..09a8a73 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1277,16 +1277,14 @@ static void usb_host_flush_ep_queue(USBDevice *dev, USBEndpoint *ep) static void usb_host_handle_reset(USBDevice *udev) { USBHostDevice *s = USB_HOST_DEVICE(udev); + int rc; trace_usb_host_reset(s->bus_num, s->addr); - if (udev->configuration == 0) { - return; + rc = libusb_reset_device(s->dh); + if (rc != 0) { + usb_host_nodev(s); } - usb_host_release_interfaces(s); - libusb_reset_device(s->dh); - usb_host_claim_interfaces(s, 0); - usb_host_ep_update(s); } static int usb_host_alloc_streams(USBDevice *udev, USBEndpoint *ep,