Skip to contentSkip to conversation

vl: remove dead code in parse_memory_options()

PATCH In review Paolo Bonzini 2 participants 2 messages Aug 5, 2022 – Aug 8, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vl: remove dead code in parse_memory_options()

mem_str will never be an empty string, because qemu_opt_get_size() fails if it encounters one:

   $ ./qemu-system-x86_64 -m size=
   qemu-system-x86_64: -m size=: Parameter size expects a non-negative number below 2^64
   Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta-
   and exabytes, respectively.
---
 softmmu/vl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
softmmu/vl.c +1 -6
index 45e919de9f..706bd7cff7 100644
@@ -1960,13 +1960,8 @@ static void parse_memory_options(void)
     prop = qdict_new();
 
     if (qemu_opt_get_size(opts, "size", 0) != 0) {
-        mem_str = qemu_opt_get(opts, "size");
-        if (!*mem_str) {
-            error_report("missing 'size' option value");
-            exit(EXIT_FAILURE);
-        }
-
         /* Fix up legacy suffix-less format */
+        mem_str = qemu_opt_get(opts, "size");
         if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
             g_autofree char *mib_str = g_strdup_printf("%sM", mem_str);
             qdict_put_str(prop, "size", mib_str);
Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Paolo Bonzini

mem_str will never be an empty string, because qemu_opt_get_size() fails if it encounters one:

   $ ./qemu-system-x86_64 -m size=
   qemu-system-x86_64: -m size=: Parameter size expects a non-negative number below 2^64
   Optional suffix k, M, G, T, P or E means kilo-, mega-, giga-, tera-, peta-
   and exabytes, respectively.
---
 softmmu/vl.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
softmmu/vl.c +0 -1
index 45e919de9f..706bd7cff7 100644
@@ -1960,13 +1960,8 @@ static void parse_memory_options(void)
     prop = qdict_new();
 
     if (qemu_opt_get_size(opts, "size", 0) != 0) {
-        mem_str = qemu_opt_get(opts, "size");

softmmu/vl.c static void parse_memory_options(void) · line 1967

Quoted 10 lines
softmmu/vl.c +1 -5
-        if (!*mem_str) {
-            error_report("missing 'size' option value");
-            exit(EXIT_FAILURE);
-        }
-
         /* Fix up legacy suffix-less format */
+        mem_str = qemu_opt_get(opts, "size");
         if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
             g_autofree char *mib_str = g_strdup_printf("%sM", mem_str);
             qdict_put_str(prop, "size", mib_str);