[Spice-devel] [PATCH spice-gtk 1/2] fixup! usb-redir: define interfaces to support emulated devices

Frediano Ziglio fziglio at redhat.com
Fri Jul 26 14:42:19 UTC 2019


Initialise SpiceUsbBackendDevice fields earlier

Allows to use spice_usb_backend_device_unref and read some
information directly from the device.
---
 src/usb-backend.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/usb-backend.c b/src/usb-backend.c
index 0bf2eccf..9c2605a0 100644
--- a/src/usb-backend.c
+++ b/src/usb-backend.c
@@ -909,19 +909,23 @@ gboolean spice_usb_backend_create_device(SpiceUsbBackend *be,
     }
 
     dev = g_new0(SpiceUsbBackendDevice, 1);
+    dev->device_info.bus = BUS_NUMBER_FOR_EMULATED_USB;
+    dev->device_info.address = address;
+    dev->device_info.device_type = dev_type;
+    dev->ref_count = 1;
 
     param->address = address;
     if (be->dev_init[dev_type](be, dev, param, &edev)) {
-        g_free(dev);
+        spice_usb_backend_device_unref(dev);
         return FALSE;
     }
+    dev->edev = edev;
 
     if (!device_ops(edev)->get_descriptor(edev, LIBUSB_DT_DEVICE, 0,
                                           (void **)&desc, &device_desc_size)
         || device_desc_size != sizeof(*desc)) {
 
-        device_ops(edev)->delete(edev);
-        g_free(dev);
+        spice_usb_backend_device_unref(dev);
         param->error = g_error_new(SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
                                    _("can't create device - internal error"));
         return FALSE;
@@ -929,17 +933,12 @@ gboolean spice_usb_backend_create_device(SpiceUsbBackend *be,
 
     be->own_devices_mask |= 1 << address;
 
-    dev->device_info.bus = BUS_NUMBER_FOR_EMULATED_USB;
-    dev->device_info.address = address;
     dev->device_info.vid = desc->idVendor;
     dev->device_info.pid = desc->idProduct;
     dev->device_info.bcdUSB = desc->bcdUSB;
     dev->device_info.class = desc->bDeviceClass;
     dev->device_info.subclass = desc->bDeviceSubClass;
     dev->device_info.protocol = desc->bDeviceProtocol;
-    dev->device_info.device_type = dev_type;
-    dev->ref_count = 1;
-    dev->edev = edev;
 
     if (be->hotplug_callback) {
         be->hotplug_callback(be->hotplug_user_data, dev, TRUE);
-- 
2.20.1



More information about the Spice-devel mailing list