The virCapabilitiesAddGuest() function can't fail. It aborts on OOM. Therefore, there's no need to check for its return value. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/bhyve/bhyve_capabilities.c | 8 +++----- src/ch/ch_conf.c | 10 ++-------- src/esx/esx_driver.c | 6 ------ src/hyperv/hyperv_driver.c | 4 ---- src/libxl/libxl_capabilities.c | 25 +++++++++++-------------- src/lxc/lxc_conf.c | 20 ++++---------------- src/openvz/openvz_conf.c | 10 ++-------- src/qemu/qemu_capabilities.c | 11 +++-------- src/security/virt-aa-helper.c | 12 ++---------- src/test/test_driver.c | 10 ++-------- src/vbox/vbox_common.c | 9 ++------- src/vmware/vmware_conf.c | 14 ++++---------- src/vz/vz_driver.c | 4 ++-- tests/testutils.c | 12 ++++-------- tests/testutilslxc.c | 18 ++++++++---------- tests/testutilsqemu.c | 11 +++-------- tests/testutilsxen.c | 33 +++++++++++++++------------------ tests/vmx2xmltest.c | 20 ++++++-------------- tests/xml2vmxtest.c | 20 ++++++-------------- 19 files changed, 79 insertions(+), 178 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 1c563c32e5..cc1c7b66b3 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -50,11 +50,9 @@ virBhyveCapsBuild(void) false, false)) == NULL) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - "bhyve", - NULL, 0, NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_X86_64, "bhyve", + NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_BHYVE, NULL, NULL, 0, NULL) == NULL) diff --git a/src/ch/ch_conf.c b/src/ch/ch_conf.c index ed0fffe5d6..d0c56f6890 100644 --- a/src/ch/ch_conf.c +++ b/src/ch/ch_conf.c @@ -65,14 +65,8 @@ virCaps *virCHDriverCapsInit(void) if (virCapabilitiesInitCaches(caps) < 0) goto cleanup; - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - caps->host.arch, - NULL, - NULL, - 0, - NULL)) == NULL) - goto cleanup; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + caps->host.arch, NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_KVM, diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 5d9687733f..f90af3c9c4 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -567,9 +567,6 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (!guest) - goto failure; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL)) goto failure; @@ -580,9 +577,6 @@ esxCapsInit(esxPrivate *priv) NULL, NULL, 0, NULL); - if (!guest) - goto failure; - if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL)) goto failure; } diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index a672901a81..aa70fdbfec 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -276,8 +276,6 @@ hypervCapsInit(hypervPrivate *priv) /* i686 caps */ guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, NULL, NULL, 0, NULL); - if (!guest) - goto error; if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, NULL, 0, NULL)) goto error; @@ -285,8 +283,6 @@ hypervCapsInit(hypervPrivate *priv) /* x86_64 caps */ guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64, NULL, NULL, 0, NULL); - if (!guest) - goto error; if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_HYPERV, NULL, NULL, 0, NULL)) goto error; diff --git a/src/libxl/libxl_capabilities.c b/src/libxl/libxl_capabilities.c index d2910cd1e4..c8020ee801 100644 --- a/src/libxl/libxl_capabilities.c +++ b/src/libxl/libxl_capabilities.c @@ -473,20 +473,17 @@ libxlCapsInitGuests(libxl_ctx *ctx, virCaps *caps) if ((machines = virCapabilitiesAllocMachines(xen_machines, 1)) == NULL) return -1; - if ((guest = virCapabilitiesAddGuest(caps, - guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM : - (guest_archs[i].pvh ? VIR_DOMAIN_OSTYPE_XENPVH : - VIR_DOMAIN_OSTYPE_XEN), - guest_archs[i].arch, - LIBXL_EXECBIN_DIR "/qemu-system-i386", - (guest_archs[i].hvm ? - LIBXL_FIRMWARE_DIR "/hvmloader" : - NULL), - 1, - machines)) == NULL) { - virCapabilitiesFreeMachines(machines, 1); - return -1; - } + guest = virCapabilitiesAddGuest(caps, + guest_archs[i].hvm ? VIR_DOMAIN_OSTYPE_HVM : + (guest_archs[i].pvh ? VIR_DOMAIN_OSTYPE_XENPVH : + VIR_DOMAIN_OSTYPE_XEN), + guest_archs[i].arch, + LIBXL_EXECBIN_DIR "/qemu-system-i386", + (guest_archs[i].hvm ? + LIBXL_FIRMWARE_DIR "/hvmloader" : + NULL), + 1, + machines); machines = NULL; if (virCapabilitiesAddGuestDomain(guest, diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index af7be88db5..a0a8dccae9 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -97,14 +97,8 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver) LIBEXECDIR))) goto error; - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_EXE, - caps->host.arch, - lxc_path, - NULL, - 0, - NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, + caps->host.arch, lxc_path, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, @@ -116,14 +110,8 @@ virCaps *virLXCDriverCapsInit(virLXCDriver *driver) /* On 64-bit hosts, we can use personality() to request a 32bit process */ if ((altArch = lxcContainerGetAlt32bitArch(caps->host.arch)) != VIR_ARCH_NONE) { - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_EXE, - altArch, - lxc_path, - NULL, - 0, - NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, + altArch, lxc_path, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 4acbf0b1a8..c6230baab4 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -156,14 +156,8 @@ virCaps *openvzCapsInit(void) if (virCapabilitiesInitCaches(caps) < 0) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_EXE, - caps->host.arch, - NULL, - NULL, - 0, - NULL)) == NULL) - return NULL; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, + caps->host.arch, NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_OPENVZ, diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 82687dbf39..2b1b1236ce 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -1043,14 +1043,9 @@ virQEMUCapsInitGuestFromBinary(virCaps *caps, /* We register kvm as the base emulator too, since we can * just give -no-kvm to disable acceleration if required */ - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - guestarch, - binary, - NULL, - nmachines, - machines)) == NULL) - goto cleanup; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + guestarch, binary, + NULL, nmachines, machines); machines = NULL; nmachines = 0; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 77b2307594..a28bec1f20 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -642,16 +642,8 @@ get_definition(vahControl * ctl, const char *xmlStr) return -1; } - if ((guest = virCapabilitiesAddGuest(ctl->caps, - ostype, - ctl->arch, - NULL, - NULL, - 0, - NULL)) == NULL) { - vah_error(ctl, 0, _("could not allocate memory")); - return -1; - } + guest = virCapabilitiesAddGuest(ctl->caps, ostype, ctl->arch, + NULL, NULL, 0, NULL); if ((virtType = virDomainVirtTypeFromString(ctl->virtType)) < 0) { vah_error(ctl, 0, _("unknown virtualization type")); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b5413cc03d..d6d1efc8a3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -345,14 +345,8 @@ testBuildCapabilities(virConnectPtr conn) } for (i = 0; i < G_N_ELEMENTS(guest_types); i++) { - if ((guest = virCapabilitiesAddGuest(caps, - guest_types[i], - VIR_ARCH_I686, - TEST_EMULATOR, - NULL, - 0, - NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, guest_types[i], VIR_ARCH_I686, + TEST_EMULATOR, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST, diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 7334254a36..6f6b7e321a 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -100,13 +100,8 @@ vboxCapsInit(void) if (virCapabilitiesInitCaches(caps) < 0) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - caps->host.arch, - NULL, - NULL, - 0, - NULL)) == NULL) + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + caps->host.arch, NULL, NULL, 0, NULL); return NULL; if (virCapabilitiesAddGuestDomain(guest, diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index af4461f2cb..3be0a845a0 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -78,11 +78,8 @@ vmwareCapsInit(void) VIR_WARN("Failed to get host CPU cache info"); /* i686 guests are always supported */ - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_I686, - NULL, NULL, 0, NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_I686, NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, @@ -103,11 +100,8 @@ vmwareCapsInit(void) (virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "vmx") || virCPUCheckFeature(caps->host.cpu->arch, caps->host.cpu, "svm")))) { - if ((guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - NULL, NULL, 0, NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_X86_64, NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index a1d05f834b..e798ddf5ee 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -83,8 +83,8 @@ vzCapsAddGuestDomain(virCaps *caps, { virCapsGuest *guest; - if ((guest = virCapabilitiesAddGuest(caps, ostype, arch, emulator, - NULL, 0, NULL)) == NULL) + guest = virCapabilitiesAddGuest(caps, ostype, arch, + emulator, NULL, 0, NULL); return -1; diff --git a/tests/testutils.c b/tests/testutils.c index d071abd6d7..1841d92061 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -903,10 +903,8 @@ virTestGenericCapsInit(void) false, false)) == NULL) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, - "/usr/bin/acme-virt", NULL, - 0, NULL)) == NULL) - return NULL; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_I686, + "/usr/bin/acme-virt", NULL, 0, NULL); if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST, NULL, NULL, 0, NULL)) return NULL; @@ -917,10 +915,8 @@ virTestGenericCapsInit(void) NULL, NULL, 0, NULL)) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64, - "/usr/bin/acme-virt", NULL, - 0, NULL)) == NULL) - return NULL; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, VIR_ARCH_X86_64, + "/usr/bin/acme-virt", NULL, 0, NULL); if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_TEST, NULL, NULL, 0, NULL)) return NULL; diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c index 0139de7437..1ee034c7b3 100644 --- a/tests/testutilslxc.c +++ b/tests/testutilslxc.c @@ -18,21 +18,19 @@ testLXCCapsInit(void) false, false)) == NULL) return NULL; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, - VIR_ARCH_I686, - "/usr/libexec/libvirt_lxc", NULL, - 0, NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, + VIR_ARCH_I686, + "/usr/libexec/libvirt_lxc", NULL, + 0, NULL); if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL)) goto error; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, - VIR_ARCH_X86_64, - "/usr/libexec/libvirt_lxc", NULL, - 0, NULL)) == NULL) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE, + VIR_ARCH_X86_64, + "/usr/libexec/libvirt_lxc", NULL, + 0, NULL); if (!virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_LXC, NULL, NULL, 0, NULL)) goto error; diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 1078a3117a..6ab7a10fb1 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -165,14 +165,9 @@ testQemuAddGuest(virCaps *caps, if (machines == NULL) goto error; - if (!(guest = virCapabilitiesAddGuest(caps, - VIR_DOMAIN_OSTYPE_HVM, - arch, - qemu_emulators[emu_arch], - NULL, - nmachines, - machines))) - goto error; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + arch, qemu_emulators[emu_arch], + NULL, nmachines, machines); machines = NULL; nmachines = 0; diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 09af6bffee..0f69a71200 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -34,12 +34,11 @@ testXLInitCaps(void) nmachines = G_N_ELEMENTS(x86_machines); if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL) goto cleanup; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - "/usr/lib/xen/bin/qemu-system-i386", - "/usr/lib/xen/boot/hvmloader", - nmachines, machines)) == NULL) - goto cleanup; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_X86_64, + "/usr/lib/xen/bin/qemu-system-i386", + "/usr/lib/xen/boot/hvmloader", + nmachines, machines); machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL, NULL, 0, NULL) == NULL) @@ -48,12 +47,11 @@ testXLInitCaps(void) if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL) goto cleanup; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XEN, - VIR_ARCH_X86_64, - "/usr/lib/xen/bin/qemu-system-i386", - NULL, - nmachines, machines)) == NULL) - goto cleanup; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XEN, + VIR_ARCH_X86_64, + "/usr/lib/xen/bin/qemu-system-i386", + NULL, + nmachines, machines); machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL, @@ -63,12 +61,11 @@ testXLInitCaps(void) if ((machines = virCapabilitiesAllocMachines(pvh_machines, nmachines)) == NULL) goto cleanup; - if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XENPVH, - VIR_ARCH_X86_64, - "/usr/lib/xen/bin/qemu-system-i386", - NULL, - nmachines, machines)) == NULL) - goto cleanup; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XENPVH, + VIR_ARCH_X86_64, + "/usr/lib/xen/bin/qemu-system-i386", + NULL, + nmachines, machines); machines = NULL; if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL, diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 98b34c9f67..e976148a29 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -31,13 +31,9 @@ testCapsInit(void) virCapabilitiesAddHostMigrateTransport(caps, "vpxmigr"); /* i686 guest */ - guest = - virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_I686, - NULL, NULL, 0, NULL); - - if (guest == NULL) - goto failure; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_I686, + NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL) == NULL) { @@ -45,13 +41,9 @@ testCapsInit(void) } /* x86_64 guest */ - guest = - virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - NULL, NULL, 0, NULL); - - if (guest == NULL) - goto failure; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_X86_64, + NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL) == NULL) { diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 60185746a8..6c65a8bcf3 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -32,13 +32,9 @@ testCapsInit(void) /* i686 guest */ - guest = - virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_I686, - NULL, NULL, 0, NULL); - - if (guest == NULL) - goto failure; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_I686, + NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL) == NULL) { @@ -46,13 +42,9 @@ testCapsInit(void) } /* x86_64 guest */ - guest = - virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, - VIR_ARCH_X86_64, - NULL, NULL, 0, NULL); - - if (guest == NULL) - goto failure; + guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM, + VIR_ARCH_X86_64, + NULL, NULL, 0, NULL); if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VMWARE, NULL, NULL, 0, NULL) == NULL) { -- 2.32.0