get_media_devices: fix get_associated_device() logic
authorMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 20:00:33 +0000 (17:00 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sat, 28 May 2011 20:00:33 +0000 (17:00 -0300)
If both last_seek and seek_device is specified and there are multiple
matches, an endless loop were happening.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
utils/libmedia_dev/get_media_devices.c

index 57538ac09125da8f28ed693208e0138f0b22b010..0a942a88ee84f18b7316c2bd0d9a22bfcd7b112a 100644 (file)
@@ -340,6 +340,13 @@ char *get_associated_device(void *opaque,
 
                /* Step 1: Find the seek node */
                for (i = 0; i < md->md_size; i++, md_ptr++) {
+                       if (last_seek && md_ptr->type == seek_type &&
+                           !strcmp(md_ptr->node, last_seek)) {
+                               found = 1;
+                               continue;
+                       }
+                       if (last_seek && !found)
+                               continue;
                        if (md_ptr->type == seek_type &&
                            !strcmp(seek_device, md_ptr->node))
                                break;
@@ -351,7 +358,8 @@ char *get_associated_device(void *opaque,
                md_ptr++;
                /* Step 2: find the associated node */
                for (;i < md->md_size && !strcmp(prev, md_ptr->device); i++, md_ptr++) {
-                       if (last_seek && !strcmp(md_ptr->node, last_seek)) {
+                       if (last_seek && md_ptr->type == seek_type &&
+                           !strcmp(md_ptr->node, last_seek)) {
                                found = 1;
                                continue;
                        }