get_media_devices: Only strip usb interface from usb device path
authorHans de Goede <hdegoede@redhat.com>
Sat, 18 Jun 2011 13:38:08 +0000 (15:38 +0200)
committerHans de Goede <hdegoede@redhat.com>
Sat, 18 Jun 2011 13:38:08 +0000 (15:38 +0200)
The old code would strip to much, leading to different usb devices on the
same hub getting seen as the same device.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
utils/libmedia_dev/get_media_devices.c

index b1f8bc7..cac006b 100644 (file)
@@ -160,15 +160,16 @@ static int get_class(char *class,
 
                        switch (bus) {
                        case MEDIA_BUS_USB:
-                               /* Remove USB sub-devices from the path */
-                               do {
-                                       p = strrchr(device, '/');
-                                       if (!p)
-                                               continue;
-                                       if (!strpbrk(p, ":."))
-                                               break;
-                                       *p = '\0';
-                               } while (1);
+                               /* Remove USB interface from the path */
+                               p = strrchr(device, '/');
+                               if (!p)
+                                       continue;
+                                /* In case we have a device where the driver
+                                   attaches directly to the usb device rather
+                                   then to an interface */
+                                if (!strchr(p, ':'))
+                                       break;
+                               *p = '\0';
                                break;
                         case MEDIA_BUS_VIRTUAL:
                                /* Don't group virtual devices */