]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: capabilities: Don't make callers check return of virQEMUCapsNew(Binary)
authorPeter Krempa <pkrempa@redhat.com>
Fri, 3 Mar 2023 08:27:45 +0000 (09:27 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 19:55:50 +0000 (20:55 +0100)
The allocation of the object itself can't fail. What can fail is the
creation of the class on a programming error. Rather than punting the
error up the stack abort() directly on the first occurence as the error
can't be fixed during runtime.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_capabilities.c
src/qemu/qemu_domain.c
tests/cputest.c
tests/qemucapabilitiestest.c
tests/qemucaps2xmltest.c
tests/qemuhotplugtest.c
tests/qemumemlocktest.c
tests/securityselinuxlabeltest.c
tests/testutilsqemu.c

index 241560b7a735c56846f0c6891e0f40aa12cf0630..0be13e7dc442acc0fe69b984ff2771fb4384f370 100644 (file)
@@ -1827,11 +1827,9 @@ virQEMUCapsNew(void)
     virQEMUCaps *qemuCaps;
 
     if (virQEMUCapsInitialize() < 0)
-        return NULL;
-
-    if (!(qemuCaps = virObjectNew(virQEMUCapsClass)))
-        return NULL;
+        abort();
 
+    qemuCaps = virObjectNew(virQEMUCapsClass);
     qemuCaps->invalidation = true;
     qemuCaps->flags = virBitmapNew(QEMU_CAPS_LAST);
 
@@ -1844,8 +1842,7 @@ virQEMUCapsNewBinary(const char *binary)
 {
     virQEMUCaps *qemuCaps = virQEMUCapsNew();
 
-    if (qemuCaps)
-        qemuCaps->binary = g_strdup(binary);
+    qemuCaps->binary = g_strdup(binary);
 
     return qemuCaps;
 }
@@ -1990,9 +1987,6 @@ virQEMUCaps *virQEMUCapsNewCopy(virQEMUCaps *qemuCaps)
     g_autoptr(virQEMUCaps) ret = virQEMUCapsNewBinary(qemuCaps->binary);
     size_t i;
 
-    if (!ret)
-        return NULL;
-
     ret->invalidation = qemuCaps->invalidation;
     ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting;
     ret->kvmSupportsSecureGuest = qemuCaps->kvmSupportsSecureGuest;
@@ -5877,12 +5871,9 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
                                 const char *kernelVersion,
                                 virCPUData* cpuData)
 {
-    g_autoptr(virQEMUCaps) qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsNewBinary(binary);
     struct stat sb;
 
-    if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
-        return NULL;
-
     /* We would also want to check faccessat if we cared about ACLs,
      * but we don't.  */
     if (stat(binary, &sb) < 0) {
@@ -5968,9 +5959,6 @@ virQEMUCapsLoadFile(const char *filename,
     virQEMUCapsCachePriv *priv = privData;
     int ret;
 
-    if (!qemuCaps)
-        return NULL;
-
     ret = virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename, false);
     if (ret < 0)
         return NULL;
index f5fd140c85781603bb91d8ec00d5fa10824b532d..e5768875ba6915e5ade788f9b03c140af3a5d20c 100644 (file)
@@ -3198,8 +3198,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
         return -1;
     }
     if (n > 0) {
-        if (!(qemuCaps = virQEMUCapsNew()))
-            return -1;
+        qemuCaps = virQEMUCapsNew();
 
         for (i = 0; i < n; i++) {
             g_autofree char *str = virXMLPropString(nodes[i], "name");
index 9b76cce2a84d20e10964eb952a78a2eb25f29289..b3253e31166d813f69f23563bcf8e63c92cac5fd 100644 (file)
@@ -458,8 +458,7 @@ cpuTestMakeQEMUCaps(const struct data *data)
                                         cpu, true, false, fail_no_props, &model) < 0)
         return NULL;
 
-    if (!(qemuCaps = virQEMUCapsNew()))
-        return NULL;
+    qemuCaps = virQEMUCapsNew();
 
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
     if (data->flags == JSON_MODELS ||
index 0066ba15fab67a1d4abba3b8dd9dc77b0f4eda66..58beeb48cbb3d147f2d00e60e9be0af1cb4ca17c 100644 (file)
@@ -95,9 +95,9 @@ testQemuCaps(const void *opaque)
     binary = g_strdup_printf("/usr/bin/qemu-system-%s",
                              data->archName);
 
-    if (!(capsActual = virQEMUCapsNewBinary(binary)) ||
-        virQEMUCapsInitQMPMonitor(capsActual,
-                                  qemuMonitorTestGetMonitor(mon)) < 0)
+    capsActual = virQEMUCapsNewBinary(binary);
+
+    if (virQEMUCapsInitQMPMonitor(capsActual, qemuMonitorTestGetMonitor(mon)) < 0)
         return -1;
 
     if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) {
index 942c8e7aa47013dd570dc5d3048e0e9a97567c94..badbce986ede70339d45350513af4007764a2518 100644 (file)
@@ -64,8 +64,7 @@ testQemuGetCaps(char *caps)
         return NULL;
     }
 
-    if (!(qemuCaps = virQEMUCapsNew()))
-        return NULL;
+    qemuCaps = virQEMUCapsNew();
 
     for (i = 0; i < n; i++) {
         g_autofree char *str = virXMLPropString(nodes[i], "name");
index 6e3d4dd80771537f9532a8445dd9efbe7d0e4637..3b54a9e957cbbbd3b82875e3a3b2d480cf095381 100644 (file)
@@ -68,8 +68,7 @@ qemuHotplugCreateObjects(virDomainXMLOption *xmlopt,
 
     priv = (*vm)->privateData;
 
-    if (!(priv->qemuCaps = virQEMUCapsNew()))
-        return -1;
+    priv->qemuCaps = virQEMUCapsNew();
 
     virQEMUCapsInitQMPBasicArch(priv->qemuCaps);
 
index 2f4fe786f5a119f6009fe680ab4ca0a69fb4b5dd..efed2324077af203d5fda56504d7d061badfac5d 100644 (file)
@@ -81,10 +81,7 @@ mymain(void)
     DO_TEST("pc-kvm", 0);
     DO_TEST("pc-tcg", 0);
 
-    if (!(qemuCaps = virQEMUCapsNew())) {
-        ret = -1;
-        goto cleanup;
-    }
+    qemuCaps = virQEMUCapsNew();
 
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
 
index 4f97edad179888475557bdd92134260801793910..30bd68b5506d2508cd8a1ef74780e34d266bd1d7 100644 (file)
@@ -322,8 +322,7 @@ mymain(void)
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
-    if (!(qemuCaps = virQEMUCapsNew()))
-        return EXIT_FAILURE;
+    qemuCaps = virQEMUCapsNew();
 
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_CIRRUS_VGA);
     virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC);
index 6f5764d98e5bec3a47aa3d170d97b186a4398aaa..e2bf598aacd70acf0dfac0930528645a64473b9d 100644 (file)
@@ -372,12 +372,11 @@ virQEMUCaps *
 qemuTestParseCapabilitiesArch(virArch arch,
                               const char *capsFile)
 {
-    g_autoptr(virQEMUCaps) qemuCaps = NULL;
     g_autofree char *binary = g_strdup_printf("/usr/bin/qemu-system-%s",
                                               virArchToString(arch));
+    g_autoptr(virQEMUCaps) qemuCaps = virQEMUCapsNewBinary(binary);
 
-    if (!(qemuCaps = virQEMUCapsNewBinary(binary)) ||
-        virQEMUCapsLoadCache(arch, qemuCaps, capsFile, true) < 0)
+    if (virQEMUCapsLoadCache(arch, qemuCaps, capsFile, true) < 0)
         return NULL;
 
     return g_steal_pointer(&qemuCaps);
@@ -896,8 +895,7 @@ testQemuInfoSetArgs(struct testQemuInfo *info,
     testQemuInfoArgName argname;
     int flag;
 
-    if (!(info->args.fakeCaps = virQEMUCapsNew()))
-        abort();
+    info->args.fakeCaps = virQEMUCapsNew();
 
     info->conf = conf;
     info->args.newargs = true;