<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 5 Feb 2016, at 18:38 PM, Jonathon Jongsma <<a href="mailto:jjongsma@redhat.com" class="">jjongsma@redhat.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Fri, 2016-02-05 at 10:21 -0600, Jonathon Jongsma wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Thu, 2016-02-04 at 16:40 -0600, Jonathon Jongsma wrote:<br class=""><blockquote type="cite" class="">On Thu, 2015-10-29 at 17:26 +0200, Dmitry Fleytman wrote:<br class=""><blockquote type="cite" class="">Hide rules order UsbDk to avoid showing specific USB<br class="">devices to Windows PnP manager.<br class=""><br class="">Spice-gtk loads hide rules for devices that should be<br class="">automatically redirected on connection to prevent Windows<br class="">from showing "New Hardware Found" wizard window for USB<br class="">devices that do not have driver on the local system.<br class=""><br class="">Signed-off-by: Dmitry Fleytman <<a href="mailto:dmitry@daynix.com" class="">dmitry@daynix.com</a>><br class="">---<br class="">src/usb-device-manager.c | 58<br class="">++++++++++++++++++++++++++++++++++++++++++++++++<br class="">1 file changed, 58 insertions(+)<br class=""><br class="">diff --git a/src/usb-device-manager.c b/src/usb-device-manager.c<br class="">index dd55276..d5fec8f 100644<br class="">--- a/src/usb-device-manager.c<br class="">+++ b/src/usb-device-manager.c<br class="">@@ -29,6 +29,10 @@<br class="">#include <errno.h><br class="">#include <libusb.h><br class=""><br class="">+#ifdef G_OS_WIN32<br class="">+#include "usbdk_api.h"<br class="">+#endif<br class="">+<br class="">#if defined(USE_GUDEV)<br class="">#include <gudev/gudev.h><br class="">#elif defined(G_OS_WIN32)<br class="">@@ -121,6 +125,8 @@ struct _SpiceUsbDeviceManagerPrivate {<br class="">    libusb_hotplug_callback_handle hp_handle;<br class="">#endif<br class="">#ifdef G_OS_WIN32<br class="">+    usbdk_api_wrapper     *usbdk_api;<br class="">+    HANDLE                 usbdk_hider_handle;<br class="">    SpiceWinUsbDriver     *installer;<br class="">#endif<br class="">    gboolean               use_usbclerk;<br class="">@@ -183,6 +189,9 @@ static void spice_usb_device_unref(SpiceUsbDevice<br class="">*device);<br class="">#ifdef G_OS_WIN32<br class="">static guint8 spice_usb_device_get_state(SpiceUsbDevice *device);<br class="">static void  spice_usb_device_set_state(SpiceUsbDevice *device, guint8<br class="">s);<br class="">+<br class="">+static void _usbdk_autoredir_enable(SpiceUsbDeviceManager *manager);<br class="">+static void _usbdk_autoredir_disable(SpiceUsbDeviceManager *manager);<br class="">#endif<br class=""><br class="">static gboolean<br class="">spice_usb_manager_device_equal_libdev(SpiceUsbDeviceManager<br class="">*manager,<br class="">@@ -364,6 +373,12 @@ static void spice_usb_device_manager_finalize(GObject<br class="">*gobject)<br class="">    g_free(priv->auto_connect_filter);<br class="">    g_free(priv->redirect_on_connect);<br class=""><br class="">+#ifdef G_OS_WIN32<br class="">+    if (!priv->use_usbclerk) {<br class="">+        if(priv->auto_connect)<br class="">+            _usbdk_autoredir_disable(self);<br class="">+    }<br class="">+#endif<br class=""></blockquote></blockquote><br class="">Another thing:<br class=""><br class="">Here you introduce this code within an<span class="Apple-converted-space"> </span><br class=""><br class="">#ifdef G_OS_WIN32<br class=""><br class="">block, but in the next commit, you change this to<span class="Apple-converted-space"> </span><br class=""><br class="">#if defined(G_OS_WIN32) && defined(USE_USBREDIR)<br class=""><br class="">If this change is necessary, it should be done in this commit, not in the next<br class="">one. But it seems that you could simply move it up a few lines to the block<br class="">where you unref the priv->installer variable, no? Or is there some reason this<br class="">has to be done after freeing auto_connect_filter and redirect_on_connect?<br class=""><br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">    /* Chain up to the parent class */<br class="">    if (G_OBJECT_CLASS(spice_usb_device_manager_parent_class)->finalize)<br class="">        G_OBJECT_CLASS(spice_usb_device_manager_parent_class)<br class="">->finalize(gobject);<br class="">@@ -415,6 +430,15 @@ static void<br class="">spice_usb_device_manager_set_property(GObject<br class="">      *gobject,<br class="">        break;<br class="">    case PROP_AUTO_CONNECT:<br class="">        priv->auto_connect = g_value_get_boolean(value);<br class=""></blockquote><br class="">It does not appear that PROP_AUTO_CONNECT is a construct-only property, so<br class="">this<br class="">property could theoretically be called multiple times. From looking at the<br class="">_usb_autoredir_(en|dis)able() functions below, it doesn't look like a good<br class="">idea<br class="">to call them multiple times. In addition, it appears racy since<br class="">_usbdk_autoredir_enable() depends on redirect_on_connect. If that property<br class="">is<br class="">not set before this one, it will return without doing anything. To avoid the<br class="">race, these calls should probably go into a 'constructed' vfunc.<br class=""><br class=""><blockquote type="cite" class="">+#ifdef G_OS_WIN32<br class="">+        if (!priv->use_usbclerk) {<br class="">+            if (priv->auto_connect) {<br class="">+                _usbdk_autoredir_enable(self);<br class="">+            } else {<br class="">+                _usbdk_autoredir_disable(self);<br class="">+            }<br class="">+        }<br class="">+#endif<br class="">        break;<br class="">    case PROP_AUTO_CONNECT_FILTER: {<br class="">        const gchar *filter = g_value_get_string(value);<br class="">@@ -1856,6 +1880,40 @@ guint8 spice_usb_device_get_state(SpiceUsbDevice<br class="">*device)<br class=""><br class="">    return info->state;<br class="">}<br class="">+static<br class="">+void _usbdk_autoredir_enable(SpiceUsbDeviceManager *manager)<br class="">+{<br class="">+    SpiceUsbDeviceManagerPrivate *priv = manager->priv;<br class="">+    g_return_if_fail(!priv->use_usbclerk);<br class="">+<br class="">+    if (priv->redirect_on_connect == NULL) {<br class=""></blockquote><br class="">as I said above, if the 'redirect-on-connect' property is not set before<br class="">'auto<br class="">-connect', this function will return without doing anythign and print a<br class="">debug<br class="">statement.<br class=""><br class=""><blockquote type="cite" class="">+        SPICE_DEBUG("No autoredirect rules, no hider setup needed");<br class="">+        return;<br class="">+    }<br class="">+<br class="">+    priv->usbdk_hider_handle = usbdk_create_hider_handle(priv<br class="">->usbdk_api);<br class=""></blockquote><br class="">Also, if this function is called multiple times, I think we'll leak the<br class="">handle<br class="">here.<br class=""></blockquote></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">... And now I notice that priv->usbdk_api has not actually been initialized in</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">this patch. It's not until patch 10 that usbdk_api_load() is called. So this</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">call will segfault unless these patches are re-ordered so that the api is loaded</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">before it's used.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>This code will not segfault because it protected by if(!use_usbclerk) condition.</div><div>This is by design to make history simpler, we introduce everything step by step</div><div>protected by if(!use_usbclerk) condition which is always false until the last patch that</div><div>sets use_usbclerk = FALSE when UsbDk is available and successfully linked. </div><div><br class=""></div><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">+    if (priv->usbdk_hider_handle == NULL) {<br class="">+        g_warning("Failed to instantiate UsbDk hider interface");<br class="">+        return;<br class="">+    }<br class="">+<br class="">+    usbdk_api_set_hide_rules(priv->usbdk_api,<br class="">+                             priv->usbdk_hider_handle,<br class="">+                             priv->redirect_on_connect);<br class="">+}<br class="">+<br class="">+static<br class="">+void _usbdk_autoredir_disable(SpiceUsbDeviceManager *manager)<br class="">+{<br class="">+    SpiceUsbDeviceManagerPrivate *priv = manager->priv;<br class="">+    g_return_if_fail(!priv->use_usbclerk);<br class="">+<br class="">+    if (priv->usbdk_hider_handle != NULL) {<br class="">+        usbdk_clear_hide_rules(priv->usbdk_api, priv<br class="">->usbdk_hider_handle);<br class="">+        usbdk_close_hider_handle(priv->usbdk_api, priv<br class="">->usbdk_hider_handle);<br class="">+        priv->usbdk_hider_handle = NULL;<br class="">+    }<br class="">+}<br class="">#endif<br class=""><br class="">static SpiceUsbDevice *spice_usb_device_ref(SpiceUsbDevice *device)<br class=""></blockquote><br class=""><br class="">Reviewed-by: Jonathon Jongsma <<a href="mailto:jjongsma@redhat.com" class="">jjongsma@redhat.com</a>><br class="">_______________________________________________<br class="">Spice-devel mailing list<br class=""><a href="mailto:Spice-devel@lists.freedesktop.org" class="">Spice-devel@lists.freedesktop.org</a><br class="">http://lists.freedesktop.org/mailman/listinfo/spice-devel<br class=""></blockquote>_______________________________________________<br class="">Spice-devel mailing list<br class=""><a href="mailto:Spice-devel@lists.freedesktop.org" class="">Spice-devel@lists.freedesktop.org</a><br class=""><a href="http://lists.freedesktop.org/mailman/listinfo/spice-devel" class="">http://lists.freedesktop.org/mailman/listinfo/spice-devel</a></blockquote></div></blockquote></div><br class=""></body></html>