[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] hostmem: fix reference to uninit mr
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] hostmem: fix reference to uninit mr |
Date: |
Fri, 10 Mar 2017 09:33:57 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 10/03/2017 05:13, Peter Xu wrote:
> 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 <address@hidden>
What is the effect of the bug? The idea was to do the initialization
once only (memory_region_size ought to be 0 when the MR is
uninitialized; now it is ugly but it made more sense when MemoryRegion
was just a C struct and not a QOM object).
Paolo
> ---
> 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
> }
>
>