From patchwork Wed Jul 13 04:18:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 9226753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 607A360868 for ; Wed, 13 Jul 2016 04:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F28F27813 for ; Wed, 13 Jul 2016 04:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F61227C38; Wed, 13 Jul 2016 04:30:13 +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=-6.9 required=2.0 tests=BAYES_00,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 A0DE627813 for ; Wed, 13 Jul 2016 04:30:12 +0000 (UTC) Received: from localhost ([::1]:45089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNBoH-0006zb-7O for patchwork-qemu-devel@patchwork.kernel.org; Wed, 13 Jul 2016 00:30:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNBo1-0006zO-Sf for qemu-devel@nongnu.org; Wed, 13 Jul 2016 00:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNBnw-0006Hg-GB for qemu-devel@nongnu.org; Wed, 13 Jul 2016 00:29:53 -0400 Received: from mga02.intel.com ([134.134.136.20]:24593) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bNBnw-0006G9-7Y for qemu-devel@nongnu.org; Wed, 13 Jul 2016 00:29:48 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP; 12 Jul 2016 21:29:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,355,1464678000"; d="scan'208";a="845270559" Received: from xiaoreal1.sh.intel.com (HELO xiaoreal1.sh.intel.com.sh.intel.com) ([10.239.48.133]) by orsmga003.jf.intel.com with ESMTP; 12 Jul 2016 21:29:42 -0700 From: Xiao Guangrong To: pbonzini@redhat.com, imammedo@redhat.com Date: Wed, 13 Jul 2016 12:18:05 +0800 Message-Id: <1468383486-108169-1-git-send-email-guangrong.xiao@linux.intel.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: 134.134.136.20 Subject: [Qemu-devel] [PATCH 1/2] hostmem: fix QEMU crash by 'info memdev' 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: Xiao Guangrong , ehabkost@redhat.com, kvm@vger.kernel.org, mst@redhat.com, gleb@kernel.org, mtosatti@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 'info memdev' crashes QEMU: (qemu) info memdev Unexpected error in parse_str() at qapi/string-input-visitor.c:111: Parameter 'null' expects an int64 value or range It is caused by null uint16List is returned if 'host-nodes' is the default value Return MAX_NODES under this case to fix this bug Signed-off-by: Xiao Guangrong --- backends/hostmem.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index 6e28be1..8dede4d 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -64,6 +64,14 @@ out: error_propagate(errp, local_err); } +static uint16List **host_memory_append_node(uint16List **node, + unsigned long value) +{ + *node = g_malloc0(sizeof(**node)); + (*node)->value = value; + return &(*node)->next; +} + static void host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -74,25 +82,23 @@ host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name, unsigned long value; value = find_first_bit(backend->host_nodes, MAX_NODES); + + node = host_memory_append_node(node, value); + if (value == MAX_NODES) { - return; + goto out; } - *node = g_malloc0(sizeof(**node)); - (*node)->value = value; - node = &(*node)->next; - do { value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1); if (value == MAX_NODES) { break; } - *node = g_malloc0(sizeof(**node)); - (*node)->value = value; - node = &(*node)->next; + node = host_memory_append_node(node, value); } while (true); +out: visit_type_uint16List(v, name, &host_nodes, errp); }