From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54156) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLFli-0005c3-0U for qemu-devel@nongnu.org; Tue, 01 Nov 2011 10:56:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RLFlY-0003Oa-MQ for qemu-devel@nongnu.org; Tue, 01 Nov 2011 10:56:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2238) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RLFlY-0003OO-Ax for qemu-devel@nongnu.org; Tue, 01 Nov 2011 10:56:40 -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 pA1EudPU020045 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 1 Nov 2011 10:56:39 -0400 From: Gerd Hoffmann Date: Tue, 1 Nov 2011 15:56:30 +0100 Message-Id: <1320159390-29797-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1320159390-29797-1-git-send-email-kraxel@redhat.com> References: <1320159390-29797-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] usb-host: fix host close List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann The whole usb_host_close() function is skipped in case the device is not in attached state. This is wrong though, only then usb_device_detach() must be skipped, all other cleanup (especially device reset and closing the file handle) still needs to be done. There are code paths where usb_host_close() is called with the device in detached state already. This fixes usb-host devices not being released and returned to the host after removing them with device_del. Signed-off-by: Gerd Hoffmann --- usb-linux.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/usb-linux.c b/usb-linux.c index 7d4d1d7..f086d57 100644 --- a/usb-linux.c +++ b/usb-linux.c @@ -1349,7 +1349,7 @@ static int usb_host_close(USBHostDevice *dev) { int i; - if (dev->fd == -1 || !dev->dev.attached) { + if (dev->fd == -1) { return -1; } @@ -1367,7 +1367,9 @@ static int usb_host_close(USBHostDevice *dev) } async_complete(dev); dev->closing = 0; - usb_device_detach(&dev->dev); + if (dev->dev.attached) { + usb_device_detach(&dev->dev); + } ioctl(dev->fd, USBDEVFS_RESET); close(dev->fd); dev->fd = -1; -- 1.7.1