From patchwork Thu Nov 1 06:09:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10663511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8E7613A4 for ; Thu, 1 Nov 2018 06:11:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87B312BC49 for ; Thu, 1 Nov 2018 06:11:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 789462BC50; Thu, 1 Nov 2018 06:11:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E1492BC49 for ; Thu, 1 Nov 2018 06:11:21 +0000 (UTC) Received: from localhost ([::1]:35563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6CO-0006Rd-Bq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Nov 2018 02:11:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6BB-0005Xn-Ti for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gI6B7-0003Z6-0b for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:05 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36220) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gI6B6-0003Yq-Qe for qemu-devel@nongnu.org; Thu, 01 Nov 2018 02:10:00 -0400 Received: by mail-pg1-x544.google.com with SMTP id z17-v6so8524088pgv.3 for ; Wed, 31 Oct 2018 23:10:00 -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=q+QyIgLhfL3GM1vaaF2J9pylFwD+5jobPpa2GQXtxHw=; b=e1Soy6G5sjE3OvDip+GT+gI0QOYgnycJsiGCrKw4ClKeWZpMOzYXLaEeFJ7OjFUS8s fgXM+iOVGIqaAvBttZMhmdZZX23vujN9cnwin/c2FSdkl897QaZy1T4wo63TPnCVahbi iaxHs3sIXhQZbpYK+k2i7IAZ45sKuvwnWWH7tpbdnnsFE+hhih5qfhz8lSRMOabwx1ei 5nRbHhQJ1JdPFIxsJIoOdFVoZ8W2NRdmFWDdsLWlEP/WWRZRC1ICBBAq3mMq6X1Clcs4 qI5ASbmQzAJTM1IIJvew140PUOZABe5F7Qefe6O3lFf8SYpgJPighRJ8oL3LrKlDG9IX buWQ== 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=q+QyIgLhfL3GM1vaaF2J9pylFwD+5jobPpa2GQXtxHw=; b=kt8KUxP5LfnTsBxxCNRhl35aeMl1Um6e0MhUpkE0tv2CEgc9m7k4lEn85alAw+5AQZ RZ34+6nv5e764tctwASxEEVUe5yRwIXnxXDU4IRHqVmcaQhRpx7XDoreq5stq9CGGd9f /UWV9n7yIvlktDynkvsdhYzt7xnrhVF1dg+tNX1nyjJb3lKnRoAuqNFpNefPGuIyt5D+ QNLtSvBVzb+fmb1YGHj2wb4cRrU9wZHAn8JzAsJDGjJh6K4Zz+BMXBq1UueXaJ2TEXdk gJ7kRdrWYa0ZeyKh0A4OCLUHBb8xY/+GlaZPNAiWJI00D2UKB3SupeIFEVEy0ZCKqniG s17w== X-Gm-Message-State: AGRZ1gKuebtQDOT68o1/XSZQKoKu5yKxsGz8AhiLhvoqAicXynArfuNP skyuCm0ZrLcHJn/hRMdXseo= X-Google-Smtp-Source: AJdET5deHB3PgdzvUaGi9GW55VsgUXJk5+hYl5IN8oETvRkQjnNGp4ZV7yvSSk+DndwlEv2501/kOQ== X-Received: by 2002:a63:608f:: with SMTP id u137mr6021796pgb.203.1541052599877; Wed, 31 Oct 2018 23:09:59 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.100]) by smtp.gmail.com with ESMTPSA id q25-v6sm48299689pfk.154.2018.10.31.23.09.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 23:09:59 -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:09:54 -0700 Message-Id: <1541052594-29132-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 1/2] hw: fw_cfg: ensure reboot_time is nonegative 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This can avoid setting a negative value to etc/boot-fail-wait. Signed-off-by: Li Qiang --- hw/nvram/fw_cfg.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 3fcfa35..dff6e06 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -199,12 +199,17 @@ static void fw_cfg_reboot(FWCfgState *s) reboot_timeout = strtol(p, &p, 10); } } - /* validate the input */ - if (reboot_timeout > 0xffff) { - error_report("reboot timeout is larger than 65535, force it to 65535."); - reboot_timeout = 0xffff; + + if (reboot_timeout >= 0) { + /* validate the input */ + if (reboot_timeout > 0xffff) { + error_report("reboot timeout is larger than 65535," + "force it to 65535."); + reboot_timeout = 0xffff; + } + fw_cfg_add_file(s, "etc/boot-fail-wait", + g_memdup(&reboot_timeout, 4), 4); } - fw_cfg_add_file(s, "etc/boot-fail-wait", g_memdup(&reboot_timeout, 4), 4); } static void fw_cfg_write(FWCfgState *s, uint8_t value) 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: 10663513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50A0713A4 for ; Thu, 1 Nov 2018 06:11:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D69C2BC49 for ; Thu, 1 Nov 2018 06:11:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E1BB2BC50; Thu, 1 Nov 2018 06:11:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B48162BC49 for ; Thu, 1 Nov 2018 06:11:36 +0000 (UTC) Received: from localhost ([::1]:35564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gI6Ce-0006dv-3X for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Nov 2018 02:11:36 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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,