The allocation of the object itself can't fail. What can fail is the
creation of the class on a programmign 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(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 20 ++++----------------
src/qemu/qemu_domain.c | 3 +--
tests/cputest.c | 3 +--
tests/qemucapabilitiestest.c | 6 +++---
tests/qemucaps2xmltest.c | 3 +--
tests/qemuhotplugtest.c | 3 +--
tests/qemumemlocktest.c | 5 +----
tests/securityselinuxlabeltest.c | 3 +--
tests/testutilsqemu.c | 8 +++-----
9 files changed, 16 insertions(+), 38 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 3cb5785baa..35f8e9828a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1828,11 +1828,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);
@@ -1845,8 +1843,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;
@@ -5858,12 +5852,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) {
@@ -5949,9 +5940,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;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a083e7e1ef..a44ac83295 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3197,8 +3197,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");
diff --git a/tests/cputest.c b/tests/cputest.c
index 9b76cce2a8..b3253e3116 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -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 ||
diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
index 0066ba15fa..58beeb48cb 100644
--- a/tests/qemucapabilitiestest.c
+++ b/tests/qemucapabilitiestest.c
@@ -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)) {
diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
index 942c8e7aa4..badbce986e 100644
--- a/tests/qemucaps2xmltest.c
+++ b/tests/qemucaps2xmltest.c
@@ -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");
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 215837fc8f..a82e35f087 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -68,8 +68,7 @@ qemuHotplugCreateObjects(virDomainXMLOption *xmlopt,
priv = (*vm)->privateData;
- if (!(priv->qemuCaps = virQEMUCapsNew()))
- return -1;
+ priv->qemuCaps = virQEMUCapsNew();
virQEMUCapsInitQMPBasicArch(priv->qemuCaps);
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index b303f70e9d..f2e1714841 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -95,10 +95,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);
diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c
index 4f97edad17..30bd68b550 100644
--- a/tests/securityselinuxlabeltest.c
+++ b/tests/securityselinuxlabeltest.c
@@ -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);
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index b5bf6829b7..ef78616062 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -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);
@@ -844,8 +843,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;
--
2.39.2