* [Qemu-devel] [PATCH 2/2] hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout
@ 2018-11-01 6:10 Li Qiang
2018-11-05 8:29 ` Gerd Hoffmann
0 siblings, 1 reply; 2+ messages in thread
From: Li Qiang @ 2018-11-01 6:10 UTC (permalink / raw)
To: pbonzini, armbru, philmd, lersek, kraxel; +Cc: qemu-devel, Li Qiang
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(-)
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,
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout
2018-11-01 6:10 [Qemu-devel] [PATCH 2/2] hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout Li Qiang
@ 2018-11-05 8:29 ` Gerd Hoffmann
0 siblings, 0 replies; 2+ messages in thread
From: Gerd Hoffmann @ 2018-11-05 8:29 UTC (permalink / raw)
To: Li Qiang; +Cc: pbonzini, armbru, philmd, lersek, qemu-devel
> + 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-05 8:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-01 6:10 [Qemu-devel] [PATCH 2/2] hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout Li Qiang
2018-11-05 8:29 ` Gerd Hoffmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.