From: Gonglei <arei.gong...@huawei.com>

In this way, we can check speed directly, don't need
call usb_device_attach(), which has other conditions,
such as checking the chardev is open.

Cc: Paolo Bonzini <pbonz...@redhat.com>
Cc: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Gonglei <arei.gong...@huawei.com>
---
 hw/usb/bus.c     | 14 +++++++++++++-
 include/hw/usb.h |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index b375293..da1eba9 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -478,7 +478,7 @@ static void usb_mask_to_str(char *dest, size_t size,
     }
 }
 
-void usb_device_attach(USBDevice *dev, Error **errp)
+void usb_check_attach(USBDevice *dev, Error **errp)
 {
     USBBus *bus = usb_bus_from_device(dev);
     USBPort *port = dev->port;
@@ -499,6 +499,18 @@ void usb_device_attach(USBDevice *dev, Error **errp)
                    bus->qbus.name, port->path, portspeed);
         return;
     }
+}
+
+void usb_device_attach(USBDevice *dev, Error **errp)
+{
+    USBPort *port = dev->port;
+    Error *local_err = NULL;
+
+    usb_check_attach(dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     dev->attached++;
     usb_attach(port);
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 8ffbba2..b20b959 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -553,6 +553,7 @@ void usb_release_port(USBDevice *dev);
 void usb_device_attach(USBDevice *dev, Error **errp);
 int usb_device_detach(USBDevice *dev);
 int usb_device_delete_addr(int busnr, int addr);
+void usb_check_attach(USBDevice *dev, Error **errp);
 
 static inline USBBus *usb_bus_from_device(USBDevice *d)
 {
-- 
1.7.12.4



Reply via email to