]> git.proxmox.com Git - mirror_qemu.git/blobdiff - block.c
block: Ignore duplicate or NULL format_name in bdrv_iterate_format
[mirror_qemu.git] / block.c
diff --git a/block.c b/block.c
index 4745712d22e571f0a59f4e7acf94938d2a418f21..100fa8679a63d120f55ddf07f200c917020ff225 100644 (file)
--- a/block.c
+++ b/block.c
@@ -3601,10 +3601,25 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
                          void *opaque)
 {
     BlockDriver *drv;
+    int count = 0;
+    const char **formats = NULL;
 
     QLIST_FOREACH(drv, &bdrv_drivers, list) {
-        it(opaque, drv->format_name);
+        if (drv->format_name) {
+            bool found = false;
+            int i = count;
+            while (formats && i && !found) {
+                found = !strcmp(formats[--i], drv->format_name);
+            }
+
+            if (!found) {
+                formats = g_realloc(formats, (count + 1) * sizeof(char *));
+                formats[count++] = drv->format_name;
+                it(opaque, drv->format_name);
+            }
+        }
     }
+    g_free(formats);
 }
 
 /* This function is to find block backend bs */