Skip to contentSkip to conversation

hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout

PATCH In review Li Qiang 2 participants 2 messages Nov 1, 2018 – Nov 5, 2018

lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 2/2 hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout

Currently the splash-time and reboot-timeout in boot_opts uses qemu_opt_get() to get a string, then convert it to a number ourselves. This is wrong. Change the opt's type to QEMU_OPT_NUMBER and use qemu_opt_get_number to parse it.

---
 hw/nvram/fw_cfg.c | 29 ++++++++---------------------
 vl.c              |  4 ++--
 2 files changed, 10 insertions(+), 23 deletions(-)
hw/nvram/fw_cfg.c +8 -21
index dff6e06..282dc6a 100644
@@ -117,9 +117,8 @@ error:
 
 static void fw_cfg_bootsplash(FWCfgState *s)
 {
-    int boot_splash_time = -1;
+    uint64_t boot_splash_time = -1;
     const char *boot_splash_filename = NULL;
-    char *p;
     char *filename, *file_data;
     gsize file_size;
     int file_type;
@@ -133,18 +132,14 @@ static void fw_cfg_bootsplash(FWCfgState *s)
         if (temp != NULL) {
             boot_splash_filename = temp;
         }
-        temp = qemu_opt_get(opts, "splash-time");
-        if (temp != NULL) {
-            p = (char *)temp;
-            boot_splash_time = strtol(p, &p, 10);
-        }
+        boot_splash_time = qemu_opt_get_number(opts, "splash-time", -1);
     }
 
     /* insert splash time if user configurated */
-    if (boot_splash_time >= 0) {
+    if ((int64_t)boot_splash_time >= 0) {
         /* validate the input */
         if (boot_splash_time > 0xffff) {
-            error_report("splash time is big than 65535, force it to 65535.");
+            error_report("splash time is big than 65535, force it to 65535");
             boot_splash_time = 0xffff;
         }
         /* use little endian format */
@@ -185,26 +180,18 @@ static void fw_cfg_bootsplash(FWCfgState *s)
 
 static void fw_cfg_reboot(FWCfgState *s)
 {
-    int reboot_timeout = -1;
-    char *p;
-    const char *temp;
+    uint64_t reboot_timeout = -1;
 
     /* get user configuration */
     QemuOptsList *plist = qemu_find_opts("boot-opts");
     QemuOpts *opts = QTAILQ_FIRST(&plist->head);
-    if (opts != NULL) {
-        temp = qemu_opt_get(opts, "reboot-timeout");
-        if (temp != NULL) {
-            p = (char *)temp;
-            reboot_timeout = strtol(p, &p, 10);
-        }
-    }
+    reboot_timeout = qemu_opt_get_number(opts, "reboot-timeout", -1);
 
-    if (reboot_timeout >= 0) {
+    if ((int64_t)reboot_timeout >= 0) {
         /* validate the input */
         if (reboot_timeout > 0xffff) {
             error_report("reboot timeout is larger than 65535,"
-                         "force it to 65535.");
+                         "force it to 65535");
             reboot_timeout = 0xffff;
         }
         fw_cfg_add_file(s, "etc/boot-fail-wait",
vl.c +2 -2
index f0bd899..60daa17 100644
@@ -336,10 +336,10 @@ static QemuOptsList qemu_boot_opts = {
             .type = QEMU_OPT_STRING,
         }, {
             .name = "splash-time",
-            .type = QEMU_OPT_STRING,
+            .type = QEMU_OPT_NUMBER,
         }, {
             .name = "reboot-timeout",
-            .type = QEMU_OPT_STRING,
+            .type = QEMU_OPT_NUMBER,
         }, {
             .name = "strict",
             .type = QEMU_OPT_BOOL,
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 1 line

+ uint64_t boot_splash_time = -1;

Hmm, why use uint64_t here ...

Quoted 1 line

+ if ((int64_t)boot_splash_time >= 0) {

... then cast it to int64_t here?

Isn't it easier to just use int64_t?

cheers,
Gerd