From nobody Thu Nov 6 15:11:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489119264125131.34871529711882; Thu, 9 Mar 2017 20:14:24 -0800 (PST) Received: from localhost ([::1]:37328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmBwb-0005Mz-MA for importer@patchew.org; Thu, 09 Mar 2017 23:14:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmBw7-0005Mg-3j for qemu-devel@nongnu.org; Thu, 09 Mar 2017 23:13:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmBw3-0006Rb-VZ for qemu-devel@nongnu.org; Thu, 09 Mar 2017 23:13:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cmBw3-0006R0-Pe for qemu-devel@nongnu.org; Thu, 09 Mar 2017 23:13:47 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF9A264A5B for ; Fri, 10 Mar 2017 04:13:47 +0000 (UTC) Received: from pxdev.xzpeter.org.com (ovpn-8-39.pek2.redhat.com [10.72.8.39]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2A4Dipv031659; Thu, 9 Mar 2017 23:13:45 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 10 Mar 2017 12:13:33 +0800 Message-Id: <1489119213-977-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 10 Mar 2017 04:13:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] hostmem: fix reference to uninit mr 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: Paolo Bonzini , Eduardo Habkost , peterx@redhat.com, Igor Mammedov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Trying to get memory region size of an uninitialized memory region is probably not a good idea. Let's just do the alloc no matter what. Signed-off-by: Peter Xu --- backends/hostmem-file.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 42efb2f..a61d1bd 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -39,6 +39,7 @@ static void file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) { HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(backend); + gchar *path; =20 if (!backend->size) { error_setg(errp, "can't create backend with size 0"); @@ -51,16 +52,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, E= rror **errp) #ifndef CONFIG_LINUX error_setg(errp, "-mem-path not supported on this host"); #else - if (!memory_region_size(&backend->mr)) { - gchar *path; - backend->force_prealloc =3D mem_prealloc; - path =3D object_get_canonical_path(OBJECT(backend)); - memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), - path, - backend->size, fb->share, - fb->mem_path, errp); - g_free(path); - } + backend->force_prealloc =3D mem_prealloc; + path =3D object_get_canonical_path(OBJECT(backend)); + memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), + path, backend->size, fb->share, + fb->mem_path, errp); + g_free(path); #endif } =20 --=20 2.7.4