On 4/22/25 10:54, Richard Henderson wrote:
On 4/22/25 07:54, Philippe Mathieu-Daudé wrote:
index f52a4f2273b..8b40735ef98 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -1581,6 +1581,33 @@ static bool is_cpu_type_supported(const MachineState 
*machine, Error **errp)
               return false;
           }
       }
+    if (mc->get_valid_cpu_types) {
+        GSList *vct = mc->get_valid_cpu_types(machine);
+        bool valid = false;
+        unsigned count = 0;
+        GSList *l;
+
+        for (l = vct; !valid && l != NULL; l = l->next) {
+            valid |= !!object_class_dynamic_cast(oc, l->data);
+            count++;
+        }
+
+        if (!valid) {
+            g_autofree char *requested = 
cpu_model_from_type(machine->cpu_type);
+            vct = g_slist_reverse(vct);
+            error_setg(errp, "Invalid CPU model: %s", requested);
+            error_append_hint(errp, "The valid models are: ");
+            for (l = vct; l != NULL; l = l->next) {
+                g_autofree char *model = cpu_model_from_type(l->data);
+                error_append_hint(errp, "%s%s", model, --count ? ", " : "");
+            }
+            error_append_hint(errp, "\n");
+        }
+        g_slist_free_full(vct, g_free);
+        if (!valid) {
+            return false;
+        }
+    }

Why use GSList instead of GPtrArray?
That would provide you the count without manually computing it,
and it would avoid the need for any sort of reverse.
I think it would also allow you to auto-free the set.


Same remark than Richard, it would remove all the checks needed, as we can simply use this array "blindly".


r~

Reply via email to