From patchwork Thu Nov 1 06:10:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 991827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OdKUdUs9"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42lvw36S54z9sV7 for ; Thu, 1 Nov 2018 17:10:59 +1100 (AEDT) Received: from localhost ([::1]:35559 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6C1-0005lb-F5 for incoming@patchwork.ozlabs.org; Thu, 01 Nov 2018 02:10:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6BQ-0005kF-I3 for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gI6BL-0003kj-LD for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:20 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:39918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gI6BL-0003kT-Ex for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:15 -0400 Received: by mail-pg1-x544.google.com with SMTP id r9-v6so8522482pgv.6 for ; Wed, 31 Oct 2018 23:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=9qDDfAXmS+ocWIRqiPNKVX+tgHmpA0MAfR9K8KjKX6E=; b=OdKUdUs98KKRnr3QtPzSXBAkhcdU5iA7n2nbKy8p7AI+2x68Z+5pbQ8QXe6bz2HUEg gAhBhDpv/CWp5dj14eSX8bcY4aSo/Xiclt1miI7oH3rhSMqV03hDR6SzmuNbJccj+fv1 MO0eWc5eOM5rjPKRdZjGIYbpHKqqIQ9PwowaqmnBJoF8Axvs3kQCq3XQ0UXftFheDRb/ KaYyPtbLJxFT11m/xZ4ikSjUTK7UmhowqkiF1O0May54ykSgd1n5NA1dxXcNAi3yBzzb 7tb7sPMmZ7e9MAfyiRpC/meGy7N3dlY4IcBHQ+Lzfot1WZSjmKoLKVCCFOiOp55MiQPp UKww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9qDDfAXmS+ocWIRqiPNKVX+tgHmpA0MAfR9K8KjKX6E=; b=hlGgGVVuo0PpnsyGTyHAGwAaz97nRhefDLxA6bLhFfOLKwkc5GcUXtuZ3yQthNFBJW Ky4lvQ+P0sBaaS/EF1ikPJjzi3+/AzvX42PyFThpna1KaMQA3+9muRyv4UQrP9721DVo lRmBMZu2n3EGM0IgPVbEsxxIgtIF6SbaVI/DHtGItyUMcn5Rfy6yxPi/Ckq9mqO91HCX YaERdNXlmzismJvZ26lFDtCEM4z/+NLqLcwvXBGhf73Y9BUUrXn+CF6YDZ0By8MMq4wx 8l/g3IqYP8VD/UHfC0cSEu2Yapt2fCkkIIPNpydTRCw0NfAsDCCkzb2va1PGWQUNWf19 ak5Q== X-Gm-Message-State: AGRZ1gIHvg5KBN5gjbBr96ViJoeW/hg84ng8dJndnNhyma320+jJuGXS Jr2FdNSyOqQNgFbIeezW9tg= X-Google-Smtp-Source: AJdET5dag9KLhklJ87eMx6HBklGBp00FQXDNO18fDdNdnD0LsJFb2oj1GQczcuwoUI9siHcVu7+Mig== X-Received: by 2002:a62:3782:: with SMTP id e124-v6mr6349634pfa.145.1541052614664; Wed, 31 Oct 2018 23:10:14 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.100]) by smtp.gmail.com with ESMTPSA id v19-v6sm32944083pgl.80.2018.10.31.23.10.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 23:10:14 -0700 (PDT) From: Li Qiang To: pbonzini@redhat.com, armbru@redhat.com, philmd@redhat.com, lersek@redhat.com, kraxel@redhat.com Date: Wed, 31 Oct 2018 23:10:09 -0700 Message-Id: <1541052609-29212-1-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH 2/2] hw: fw_cfg: use qemu_opt_get_number to get splash-time and reboot-timeout X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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,