[Spice-devel] [spice-gtk v2 05/13] win-usb-dev: strict comparison of USB devices

Yuri Benditovich yuri.benditovich at daynix.com
Tue Mar 19 05:56:00 UTC 2019


If on device change the new device has the same bus:address
as existing device, win-usb-dev does not emit signal of
device change (for example, when due to some reason the
'redirecting' property is set for long time and during this
time one of devices is changed).
Make device comparison more strict: check not only bus:addr,
but also vid:pid.

Signed-off-by: Yuri Benditovich <yuri.benditovich at daynix.com>
---
 src/win-usb-dev.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/win-usb-dev.c b/src/win-usb-dev.c
index b08bf02..52e61a8 100644
--- a/src/win-usb-dev.c
+++ b/src/win-usb-dev.c
@@ -385,20 +385,21 @@ static gboolean get_usb_dev_info(libusb_device *dev, GUdevDeviceInfo *udevinfo)
     return TRUE;
 }
 
-/* Only bus:addr are compared */
+/* comparing bus:addr and vid:pid */
 static gint gudev_devices_differ(gconstpointer a, gconstpointer b)
 {
     GUdevDeviceInfo *ai, *bi;
-    gboolean same_bus;
-    gboolean same_addr;
+    gboolean same_bus, same_addr, same_vid, same_pid;
 
     ai = G_UDEV_DEVICE(a)->priv->udevinfo;
     bi = G_UDEV_DEVICE(b)->priv->udevinfo;
 
     same_bus = (ai->bus == bi->bus);
     same_addr = (ai->addr == bi->addr);
+    same_vid = (ai->vid == bi->vid);
+    same_pid = (ai->pid == bi->pid);
 
-    return (same_bus && same_addr) ? 0 : -1;
+    return (same_bus && same_addr && same_vid && same_pid) ? 0 : -1;
 }
 
 static void notify_dev_state_change(GUdevClient *self,
-- 
2.17.1



More information about the Spice-devel mailing list