From patchwork Sat Jun 14 04:48:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 359751 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0AE4A14009F for ; Sat, 14 Jun 2014 14:53:00 +1000 (EST) Received: from localhost ([::1]:34180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wvfxa-0003F3-27 for incoming@patchwork.ozlabs.org; Sat, 14 Jun 2014 00:52:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wvfvs-00005u-8Y for qemu-devel@nongnu.org; Sat, 14 Jun 2014 00:51:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wvfvk-0000lA-7k for qemu-devel@nongnu.org; Sat, 14 Jun 2014 00:51:12 -0400 Received: from [59.151.112.132] (port=42909 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wvfvj-0000iq-Ta for qemu-devel@nongnu.org; Sat, 14 Jun 2014 00:51:04 -0400 X-IronPort-AV: E=Sophos;i="5.00,707,1396972800"; d="scan'208";a="31897848" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 Jun 2014 12:48:24 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s5E4p2NO014773; Sat, 14 Jun 2014 12:51:02 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com (10.167.226.102) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Sat, 14 Jun 2014 12:51:09 +0800 From: Hu Tao To: Date: Sat, 14 Jun 2014 12:48:59 +0800 Message-ID: <5a1cdce658586b46e49ce906d56aeff502bc24bd.1402720673.git.hutao@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.102] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Yasunori Goto , Paolo Bonzini , Igor Mammedov , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH RFC 4/4] memory-backend-file: error out if failed to allocate memory X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If user adds a memory-backend-file object using object_add command, specifying a non-existing directory for property mem-path, qemu will core dump with message: /nonexistingdir: No such file or directory Bad ram offset fffffffffffff000 Aborted (core dumped) This patch fixes this problem. Signed-off-by: Hu Tao --- backends/hostmem-file.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 5179994..70172d1 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -55,6 +55,9 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) object_get_canonical_path(OBJECT(backend)), backend->size, fb->share, fb->mem_path, errp); + if (backend->mr.ram_addr == -1) { + error_setg(errp, "failed to allocate memory"); + } } #endif }