qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	peterx@redhat.com, Eduardo Habkost <ehabkost@redhat.com>
Subject: [Qemu-devel] [PATCH] hostmem: fix reference to uninit mr
Date: Fri, 10 Mar 2017 12:13:33 +0800	[thread overview]
Message-ID: <1489119213-977-1-git-send-email-peterx@redhat.com> (raw)

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 <peterx@redhat.com>
---
 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 = MEMORY_BACKEND_FILE(backend);
+    gchar *path;
 
     if (!backend->size) {
         error_setg(errp, "can't create backend with size 0");
@@ -51,16 +52,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **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 = mem_prealloc;
-        path = 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 = mem_prealloc;
+    path = 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
 }
 
-- 
2.7.4

             reply	other threads:[~2017-03-10  4:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-10  4:13 Peter Xu [this message]
2017-03-10  8:33 ` [Qemu-devel] [PATCH] hostmem: fix reference to uninit mr Paolo Bonzini
2017-03-10  8:59   ` Peter Xu
2017-03-10  9:17     ` Peter Maydell
2017-03-10  9:36       ` Peter Xu
2017-03-10 10:06         ` Paolo Bonzini
2017-03-10  9:19     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489119213-977-1-git-send-email-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).