[PATCH v3 09/13] Add additional locks to critical sections of redirection flows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kirill Moizik <kmoizik@xxxxxxxxxx>

---
 src/channel-usbredir.c   |  6 ++++++
 src/usb-device-manager.c | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index 699b845..dffd2b5 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -731,12 +731,17 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
     priv->read_buf = buf;
     priv->read_buf_size = size;
 
+    g_mutex_lock(priv->flows_mutex);
     r = usbredirhost_read_guest_data(priv->host);
     if (r != 0) {
         SpiceUsbDevice *spice_device = priv->spice_device;
         gchar *desc;
         GError *err;
 
+        if (spice_device == NULL)
+        {
+            g_mutex_unlock(priv->flows_mutex);
+        }
         g_return_if_fail(spice_device != NULL);
 
         desc = spice_usb_device_get_description(spice_device, NULL);
@@ -774,6 +779,7 @@ static void usbredir_handle_msg(SpiceChannel *c, SpiceMsgIn *in)
 
         g_error_free(err);
     }
+        g_mutex_unlock(priv->flows_mutex);
 }
 
 #endif /* USE_USBREDIR */
diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c
index ebd9307..b666671 100644
--- a/src/usb-device-manager.c
+++ b/src/usb-device-manager.c
@@ -1399,9 +1399,13 @@ static SpiceUsbredirChannel *spice_usb_device_manager_get_channel_for_dev(
 
     for (i = 0; i < priv->channels->len; i++) {
         SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
+        spice_usbredir_channel_lock(channel);
         libusb_device *libdev = spice_usbredir_channel_get_device(channel);
-        if (spice_usb_manager_device_equal_libdev(manager, device, libdev))
+        if (spice_usb_manager_device_equal_libdev(manager, device, libdev)) {
+            spice_usbredir_channel_unlock(channel);
             return channel;
+        }
+        spice_usbredir_channel_unlock(channel);
     }
 #endif
     return NULL;
@@ -1832,9 +1836,13 @@ spice_usb_device_manager_can_redirect_device(SpiceUsbDeviceManager  *self,
     /* Check if there are free channels */
     for (i = 0; i < priv->channels->len; i++) {
         SpiceUsbredirChannel *channel = g_ptr_array_index(priv->channels, i);
+        spice_usbredir_channel_lock(channel);
 
-        if (!spice_usbredir_channel_get_device(channel))
+        if (!spice_usbredir_channel_get_device(channel)){
+            spice_usbredir_channel_unlock(channel);
             break;
+        }
+        spice_usbredir_channel_unlock(channel);
     }
     if (i == priv->channels->len) {
         g_set_error_literal(err, SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
-- 
2.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]