From 9614e013e4cf2b5e7471390188df0f418b07829a Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 23 Jun 2011 12:42:28 -0300
Subject: [RHEL6 qemu-kvm PATCH 112/115] usb-linux: only cleanup in host_close when host_open was successful. (cherry picked from commit 1f45a81bef8bc4aee98e29bd28bfb21edb623879)

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1308832951-8995-113-git-send-email-kraxel@redhat.com>
Patchwork-id: 27913
O-Subject: [RHEL-6.2 kvm PATCH 112/115] usb-linux: only cleanup in host_close when host_open was successful. (cherry picked from commit 1f45a81bef8bc4aee98e29bd28bfb21edb623879)
Bugzilla: 561414 632299 645351 711354
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

Conflicts:

	usb-linux.c

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 usb-linux.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 usb-linux.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index e48ab96..04c2851 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1151,9 +1151,10 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
     return 0;
 
 fail:
-    dev->fd = -1;
-    if (fd != -1)
-        close(fd);
+    if (dev->fd != -1) {
+        close(dev->fd);
+        dev->fd = -1;
+    }
     return -1;
 }
 
@@ -1161,7 +1162,7 @@ static int usb_host_close(USBHostDevice *dev)
 {
     int i;
 
-    if (dev->fd == -1) {
+    if (dev->fd == -1 || !dev->dev.attached) {
         return -1;
     }
 
-- 
1.7.3.2

