diff mbox

[v6,10/33] hostmem-file: clean up memory allocation

Message ID 1446184587-142784-11-git-send-email-guangrong.xiao@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xiao Guangrong Oct. 30, 2015, 5:56 a.m. UTC
- hostmem-file.c is compiled only if CONFIG_LINUX is enabled so that is
  unnecessary to do the same check in the source file

- the interface, HostMemoryBackendClass->alloc(), is not called many
  times, do not need to check if the memory-region is initialized

Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
---
 backends/hostmem-file.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

Comments

Vladimir Sementsov-Ogievskiy Oct. 30, 2015, 2:54 p.m. UTC | #1
On 30.10.2015 08:56, Xiao Guangrong wrote:
> - hostmem-file.c is compiled only if CONFIG_LINUX is enabled so that is
>    unnecessary to do the same check in the source file
>
> - the interface, HostMemoryBackendClass->alloc(), is not called many
>    times, do not need to check if the memory-region is initialized
>
> Signed-off-by: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> ---
>   backends/hostmem-file.c | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index e9b6d21..9097a57 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -46,17 +46,12 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
>           error_setg(errp, "mem-path property not set");
>           return;
>       }
> -#ifndef CONFIG_LINUX
> -    error_setg(errp, "-mem-path not supported on this host");
> -#else
> -    if (!memory_region_size(&backend->mr)) {
> -        backend->force_prealloc = mem_prealloc;
> -        memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
> +
> +    backend->force_prealloc = mem_prealloc;
> +    memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
>                                    object_get_canonical_path(OBJECT(backend)),
>                                    backend->size, fb->share,
>                                    fb->mem_path, errp);
> -    }
> -#endif
>   }
>   
>   static void

Similar function for memory backend (the only other 
HostMemoryBackendClass) - ram_backend_memory_alloc - has not such check 
too. It's ok..

Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
diff mbox

Patch

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index e9b6d21..9097a57 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -46,17 +46,12 @@  file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
         error_setg(errp, "mem-path property not set");
         return;
     }
-#ifndef CONFIG_LINUX
-    error_setg(errp, "-mem-path not supported on this host");
-#else
-    if (!memory_region_size(&backend->mr)) {
-        backend->force_prealloc = mem_prealloc;
-        memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
+
+    backend->force_prealloc = mem_prealloc;
+    memory_region_init_ram_from_file(&backend->mr, OBJECT(backend),
                                  object_get_canonical_path(OBJECT(backend)),
                                  backend->size, fb->share,
                                  fb->mem_path, errp);
-    }
-#endif
 }
 
 static void