diff mbox series

[4/4] vl: Only choose enabled accelerators in configure_accelerators

Message ID 20200109021710.1219-5-richard.henderson@linaro.org
State New
Headers show
Series vl: Fixes for cleanups to -accel | expand

Commit Message

Richard Henderson Jan. 9, 2020, 2:17 a.m. UTC
By choosing "tcg:kvm" when kvm is not enabled, we generate
an incorrect warning: "invalid accelerator kvm".

Presumably the inverse is also true with --disable-tcg.

Fixes: 28a0961757fc
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 vl.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

-- 
2.20.1
diff mbox series

Patch

diff --git a/vl.c b/vl.c
index 887dbfbb5d..9b7651c80d 100644
--- a/vl.c
+++ b/vl.c
@@ -2759,11 +2759,10 @@  static void configure_accelerators(const char *progname)
 
         if (accel == NULL) {
             /* Select the default accelerator */
-            if (!accel_find("tcg") && !accel_find("kvm")) {
-                error_report("No accelerator selected and"
-                             " no default accelerator available");
-                exit(1);
-            } else {
+            bool have_tcg = accel_find("tcg");
+            bool have_kvm = accel_find("kvm");
+
+            if (have_tcg && have_kvm) {
                 int pnlen = strlen(progname);
                 if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
                     /* If the program name ends with "kvm", we prefer KVM */
@@ -2771,9 +2770,16 @@  static void configure_accelerators(const char *progname)
                 } else {
                     accel = "tcg:kvm";
                 }
+            } else if (have_kvm) {
+                accel = "kvm";
+            } else if (have_tcg) {
+                accel = "tcg";
+            } else {
+                error_report("No accelerator selected and"
+                             " no default accelerator available");
+                exit(1);
             }
         }
-
         accel_list = g_strsplit(accel, ":", 0);
 
         for (tmp = accel_list; *tmp; tmp++) {