[PATCH 3/5] cpu_s390.c: modernize virCPUs390Update

Daniel Henrique Barboza danielhb413 at gmail.com
Fri May 22 19:56:18 UTC 2020


Use automatic cleanup of variables.

Signed-off-by: Daniel Henrique Barboza <danielhb413 at gmail.com>
---
 src/cpu/cpu_s390.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c
index dd030c5a11..c1c5686244 100644
--- a/src/cpu/cpu_s390.c
+++ b/src/cpu/cpu_s390.c
@@ -45,8 +45,7 @@ static int
 virCPUs390Update(virCPUDefPtr guest,
                  const virCPUDef *host)
 {
-    virCPUDefPtr updated = NULL;
-    int ret = -1;
+    g_autoptr(virCPUDef) updated = NULL;
     size_t i;
 
     if (guest->mode == VIR_CPU_MODE_CUSTOM) {
@@ -58,37 +57,34 @@ virCPUs390Update(virCPUDefPtr guest,
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("optional CPU features are not supported"));
         }
-        goto cleanup;
+        return -1;
     }
 
     if (!host) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("unknown host CPU model"));
-        goto cleanup;
+        return -1;
     }
 
     if (!(updated = virCPUDefCopyWithoutModel(guest)))
-        goto cleanup;
+        return -1;
 
     updated->mode = VIR_CPU_MODE_CUSTOM;
     if (virCPUDefCopyModel(updated, host, true) < 0)
-        goto cleanup;
+        return -1;
 
     for (i = 0; i < guest->nfeatures; i++) {
        if (virCPUDefUpdateFeature(updated,
                                   guest->features[i].name,
                                   guest->features[i].policy) < 0)
-           goto cleanup;
+           return -1;
     }
 
     virCPUDefStealModel(guest, updated, false);
     guest->mode = VIR_CPU_MODE_CUSTOM;
     guest->match = VIR_CPU_MATCH_EXACT;
-    ret = 0;
 
- cleanup:
-    virCPUDefFree(updated);
-    return ret;
+    return 0;
 }
 
 
-- 
2.26.2




More information about the libvir-list mailing list