diff mbox series

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

Message ID 1541052609-29212-1-git-send-email-liq3ea@gmail.com
State New
Headers show
Series fw_cfg reboot_time and splash_time fix | expand

Commit Message

Li Qiang Nov. 1, 2018, 6:10 a.m. UTC
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.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 hw/nvram/fw_cfg.c | 29 ++++++++---------------------
 vl.c              |  4 ++--
 2 files changed, 10 insertions(+), 23 deletions(-)

Comments

Gerd Hoffmann Nov. 5, 2018, 8:29 a.m. UTC | #1
> +    uint64_t boot_splash_time = -1;

Hmm, why use uint64_t here ...

> +    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
diff mbox series

Patch

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index dff6e06..282dc6a 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -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",
diff --git a/vl.c b/vl.c
index f0bd899..60daa17 100644
--- a/vl.c
+++ b/vl.c
@@ -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,