[PATCH] hostmem: simplify the code

Paolo Bonzini posted 1 patch 5 months, 3 weeks ago
Failed in applying to current master (apply log)
backends/hostmem.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
[PATCH] hostmem: simplify the code
Posted by Paolo Bonzini 5 months, 3 weeks ago
No semantic change, just simpler control flow.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 backends/hostmem.c | 24 ++++++++----------------
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 37be93c8bb3..33baca6a974 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -178,12 +178,8 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
         return;
     }
 
-    if (!host_memory_backend_mr_inited(backend)) {
-        backend->merge = value;
-        return;
-    }
-
-    if (value != backend->merge) {
+    if (!host_memory_backend_mr_inited(backend) &&
+        value != backend->merge) {
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
@@ -194,9 +190,9 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
                              object_get_typename(obj));
             return;
         }
-
-        backend->merge = value;
     }
+
+    backend->merge = value;
 }
 
 static bool host_memory_backend_get_dump(Object *obj, Error **errp)
@@ -218,12 +214,8 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
         return;
     }
 
-    if (!host_memory_backend_mr_inited(backend)) {
-        backend->dump = value;
-        return;
-    }
-
-    if (value != backend->dump) {
+    if (host_memory_backend_mr_inited(backend) &&
+        value != backend->dump) {
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
@@ -234,9 +226,9 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
                              object_get_typename(obj));
             return;
         }
-
-        backend->dump = value;
     }
+
+    backend->dump = value;
 }
 
 static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
-- 
2.45.1
Re: [PATCH] hostmem: simplify the code
Posted by Philippe Mathieu-Daudé 5 months, 3 weeks ago
On 6/6/24 11:37, Paolo Bonzini wrote:
> No semantic change, just simpler control flow.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   backends/hostmem.c | 24 ++++++++----------------
>   1 file changed, 8 insertions(+), 16 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>