[PATCH] softmmu/vl: improve select_machine() function

Vladimir Sementsov-Ogievskiy posted 1 patch 9 months, 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230725174730.1185838-1-vsementsov@yandex-team.ru
Maintainers: Paolo Bonzini <pbonzini@redhat.com>
softmmu/vl.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
[PATCH] softmmu/vl: improve select_machine() function
Posted by Vladimir Sementsov-Ogievskiy 9 months, 2 weeks ago
 - put machine name into error message (helps debugging CI)
 - fix style (over-80 lines)
 - use g_autoptr
 - drop extra error propagation

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
 softmmu/vl.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/softmmu/vl.c b/softmmu/vl.c
index b0b96f67fa..77fe9e52ea 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -1596,27 +1596,25 @@ static const QEMUOption *lookup_opt(int argc, char **argv,
 static MachineClass *select_machine(QDict *qdict, Error **errp)
 {
     const char *optarg = qdict_get_try_str(qdict, "type");
-    GSList *machines = object_class_get_list(TYPE_MACHINE, false);
+    g_autoptr(GSList) machines = object_class_get_list(TYPE_MACHINE, false);
     MachineClass *machine_class;
-    Error *local_err = NULL;
 
     if (optarg) {
         machine_class = find_machine(optarg, machines);
-        qdict_del(qdict, "type");
         if (!machine_class) {
-            error_setg(&local_err, "unsupported machine type");
+            error_setg(errp, "unsupported machine type: \"%s\"", optarg);
         }
+        qdict_del(qdict, "type");
     } else {
         machine_class = find_default_machine(machines);
         if (!machine_class) {
-            error_setg(&local_err, "No machine specified, and there is no default");
+            error_setg(errp, "No machine specified, and there is no default");
         }
     }
 
-    g_slist_free(machines);
-    if (local_err) {
-        error_append_hint(&local_err, "Use -machine help to list supported machines\n");
-        error_propagate(errp, local_err);
+    if (!machine_class) {
+        error_append_hint(errp,
+                          "Use -machine help to list supported machines\n");
     }
     return machine_class;
 }
-- 
2.34.1
Re: [PATCH] softmmu/vl: improve select_machine() function
Posted by Vladimir Sementsov-Ogievskiy 7 months ago
On 25.07.23 20:47, Vladimir Sementsov-Ogievskiy wrote:
>   - put machine name into error message (helps debugging CI)
>   - fix style (over-80 lines)
>   - use g_autoptr
>   - drop extra error propagation
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>

ping ;)

-- 
Best regards,
Vladimir