]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: refactor libxlCapsInitCPU
authorJán Tomko <jtomko@redhat.com>
Sun, 5 Sep 2021 19:08:24 +0000 (21:08 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 8 Sep 2021 14:19:55 +0000 (16:19 +0200)
Use g_auto, g_steal_pointer and remove unnecessary labels.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
src/libxl/libxl_capabilities.c

index 9d0ed921bd62ec47404422ba3db9a0b1a1170b92..38a9b36d8bc4866735858b63723b0d7e3f5faec0 100644 (file)
@@ -138,9 +138,8 @@ libxlCapsNodeData(virCPUDef *cpu, libxl_hwcap hwcap)
 static int
 libxlCapsInitCPU(virCaps *caps, libxl_physinfo *phy_info)
 {
-    virCPUData *data = NULL;
-    virCPUDef *cpu = NULL;
-    int ret = -1;
+    g_autoptr(virCPUData) data = NULL;
+    g_autoptr(virCPUDef) cpu = NULL;
     int host_pae;
     int host_lm;
 
@@ -153,7 +152,7 @@ libxlCapsInitCPU(virCaps *caps, libxl_physinfo *phy_info)
     host_pae = phy_info->hw_cap[0] & LIBXL_X86_FEATURE_PAE_MASK;
     if (host_pae &&
         virCapabilitiesAddHostFeature(caps, "pae") < 0)
-        goto error;
+        return -1;
 
     host_lm = (phy_info->hw_cap[2] & LIBXL_X86_FEATURE_LM_MASK);
     if (host_lm)
@@ -171,20 +170,11 @@ libxlCapsInitCPU(virCaps *caps, libxl_physinfo *phy_info)
         cpuDecode(cpu, data, NULL) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Failed to initialize host cpu features"));
-        goto error;
+        return -1;
     }
 
-    caps->host.cpu = cpu;
-    ret = 0;
-
- cleanup:
-    virCPUDataFree(data);
-
-    return ret;
-
- error:
-    virCPUDefFree(cpu);
-    goto cleanup;
+    caps->host.cpu = g_steal_pointer(&cpu);
+    return 0;
 }
 
 static int