I think it makes no sense to have else branches after return or
goto as it will never reach them in cases it should not. This
patch makes the code more readable (at least to me).
Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
src/libvirt.c | 3 ++-
src/qemu/qemu_agent.c | 6 +++---
src/qemu/qemu_alias.c | 9 +++++----
src/qemu/qemu_capabilities.c | 4 ++--
src/qemu/qemu_cgroup.c | 9 +++------
src/qemu/qemu_conf.c | 11 +++++------
src/qemu/qemu_domain_address.c | 11 +++++------
src/qemu/qemu_domainjob.c | 3 +--
src/qemu/qemu_driver.c | 32 ++++++++++++++++----------------
9 files changed, 42 insertions(+), 46 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 80bdcd1db3..ef9fc403d0 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -663,7 +663,8 @@ virStateInitialize(bool privileged,
virStateDriverTab[i]->name,
virGetLastErrorMessage());
return -1;
- } else if (ret == VIR_DRV_STATE_INIT_SKIPPED && mandatory) {
+ }
+ if (ret == VIR_DRV_STATE_INIT_SKIPPED && mandatory) {
VIR_ERROR(_("Initialization of mandatory %s state driver
skipped"),
virStateDriverTab[i]->name);
return -1;
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index c3b02569cd..75eb1620c0 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -989,8 +989,7 @@ qemuAgentCommandName(virJSONValue *cmd)
const char *name = virJSONValueObjectGetString(cmd, "execute");
if (name)
return name;
- else
- return "<unknown>";
+ return "<unknown>";
}
static int
@@ -1029,7 +1028,8 @@ qemuAgentCheckError(virJSONValue *cmd,
qemuAgentStringifyError(error));
return -1;
- } else if (!virJSONValueObjectHasKey(reply, "return")) {
+ }
+ if (!virJSONValueObjectHasKey(reply, "return")) {
g_autofree char *cmdstr = virJSONValueToString(cmd, false);
g_autofree char *replystr = virJSONValueToString(reply, false);
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index a36f346592..5b525415de 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -137,7 +137,8 @@ qemuAssignDeviceControllerAlias(virDomainDef *domainDef,
*/
controller->info.alias = g_strdup("pci");
return 0;
- } else if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) {
+ }
+ if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT) {
/* The pcie-root controller on Q35 machinetypes uses a
* different naming convention ("pcie.0"), because it is
* hardcoded that way in qemu.
@@ -151,7 +152,8 @@ qemuAssignDeviceControllerAlias(virDomainDef *domainDef,
*/
controller->info.alias = g_strdup_printf("pci.%d",
controller->idx);
return 0;
- } else if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE) {
+ }
+ if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE) {
/* for any machine based on e.g. I440FX or G3Beige, the
* first (and currently only) IDE controller is an integrated
* controller hardcoded with id "ide"
@@ -821,8 +823,7 @@ qemuAliasForSecret(const char *parentalias,
{
if (obj)
return g_strdup_printf("%s-%s-secret0", parentalias, obj);
- else
- return g_strdup_printf("%s-secret0", parentalias);
+ return g_strdup_printf("%s-secret0", parentalias);
}
/* qemuAliasTLSObjFromSrcAlias
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a4c492dde2..3b63996170 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -773,9 +773,9 @@ const char *virQEMUCapsArchToString(virArch arch)
{
if (arch == VIR_ARCH_I686)
return "i386";
- else if (arch == VIR_ARCH_ARMV6L || arch == VIR_ARCH_ARMV7L)
+ if (arch == VIR_ARCH_ARMV6L || arch == VIR_ARCH_ARMV7L)
return "arm";
- else if (arch == VIR_ARCH_OR32)
+ if (arch == VIR_ARCH_OR32)
return "or32";
return virArchToString(arch);
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 1e7b562b33..bcdfa90759 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -608,9 +608,8 @@ qemuSetupBlkioCgroup(virDomainObj *vm)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Block I/O tuning is not available on this
host"));
return -1;
- } else {
- return 0;
}
+ return 0;
}
return virDomainCgroupSetupBlkio(priv->cgroup, vm->def->blkio);
@@ -629,9 +628,8 @@ qemuSetupMemoryCgroup(virDomainObj *vm)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Memory cgroup is not available on this host"));
return -1;
- } else {
- return 0;
}
+ return 0;
}
return virDomainCgroupSetupMemtune(priv->cgroup, vm->def->mem);
@@ -891,9 +889,8 @@ qemuSetupCpuCgroup(virDomainObj *vm)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("CPU tuning is not available on this host"));
return -1;
- } else {
- return 0;
}
+ return 0;
}
if (vm->def->cputune.sharesSpecified) {
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 0451bc70ac..bbb05a4e81 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1001,12 +1001,12 @@ virQEMUDriverConfigLoadMemoryEntry(virQEMUDriverConfig *cfg,
g_autofree char *dir = NULL;
int rc;
- if ((rc = virConfGetValueString(conf, "memory_backing_dir", &dir)) <
0) {
+ if ((rc = virConfGetValueString(conf, "memory_backing_dir", &dir)) <
0)
return -1;
- } else if (rc > 0) {
+
+ if (rc > 0) {
VIR_FREE(cfg->memoryBackingDir);
cfg->memoryBackingDir = g_strdup_printf("%s/libvirt/qemu", dir);
- return 0;
}
return 0;
@@ -1777,11 +1777,10 @@ qemuSharedDeviceAddRemoveInternal(virQEMUDriver *driver,
if (dev->type == VIR_DOMAIN_DEVICE_DISK)
return qemuSharedDiskAddRemoveInternal(driver, dev->data.disk,
name, addDevice);
- else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
+ if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
return qemuSharedHostdevAddRemoveInternal(driver, dev->data.hostdev,
name, addDevice);
- else
- return 0;
+ return 0;
}
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 9abe2b84c8..2948630b75 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -58,13 +58,13 @@ qemuDomainGetSCSIControllerModel(const virDomainDef *def,
if (qemuDomainIsPSeries(def))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI;
- else if (ARCH_IS_S390(def->os.arch))
+ if (ARCH_IS_S390(def->os.arch))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI;
- else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_LSI))
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_LSI))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC;
- else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_SCSI))
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_SCSI))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI;
- else if (qemuDomainHasBuiltinESP(def))
+ if (qemuDomainHasBuiltinESP(def))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_NCR53C90;
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1589,9 +1589,8 @@ qemuDomainCollectPCIAddress(virDomainDef *def G_GNUC_UNUSED,
_("Bus 0 must be PCI for integrated PIIX3 "
"USB or IDE controllers"));
return -1;
- } else {
- return 0;
}
+ return 0;
}
}
diff --git a/src/qemu/qemu_domainjob.c b/src/qemu/qemu_domainjob.c
index 03a8d9ba5f..cff8d7bb83 100644
--- a/src/qemu/qemu_domainjob.c
+++ b/src/qemu/qemu_domainjob.c
@@ -1036,8 +1036,7 @@ int qemuDomainObjBeginJob(virQEMUDriver *driver,
QEMU_AGENT_JOB_NONE,
QEMU_ASYNC_JOB_NONE, false) < 0)
return -1;
- else
- return 0;
+ return 0;
}
/**
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 16d449913c..437bf63cd4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1819,7 +1819,8 @@ static int qemuDomainSuspend(virDomainPtr dom)
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is pmsuspended"));
goto endjob;
- } else if (state != VIR_DOMAIN_PAUSED) {
+ }
+ if (state != VIR_DOMAIN_PAUSED) {
if (qemuProcessStopCPUs(driver, vm, reason, QEMU_ASYNC_JOB_NONE) < 0)
goto endjob;
}
@@ -1861,13 +1862,15 @@ static int qemuDomainResume(virDomainPtr dom)
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is pmsuspended"));
goto endjob;
- } else if (state == VIR_DOMAIN_RUNNING) {
+ }
+ if (state == VIR_DOMAIN_RUNNING) {
virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("domain is already running"));
goto endjob;
- } else if ((state == VIR_DOMAIN_CRASHED &&
- reason == VIR_DOMAIN_CRASHED_PANICKED) ||
- state == VIR_DOMAIN_PAUSED) {
+ }
+ if ((state == VIR_DOMAIN_CRASHED &&
+ reason == VIR_DOMAIN_CRASHED_PANICKED) ||
+ state == VIR_DOMAIN_PAUSED) {
if (qemuProcessStartCPUs(driver, vm,
VIR_DOMAIN_RUNNING_UNPAUSED,
QEMU_ASYNC_JOB_NONE) < 0) {
@@ -16358,9 +16361,9 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
*nparams = maxparams;
ret = 0;
goto endjob;
- } else if (*nparams < maxparams) {
- maxparams = *nparams;
}
+ if (*nparams < maxparams)
+ maxparams = *nparams;
*nparams = 0;
@@ -20428,29 +20431,26 @@ qemuDomainGetGuestInfo(virDomainPtr dom,
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_FILESYSTEM) {
rc = qemuAgentGetFSInfo(agent, &agentfsinfo, report_unsupported);
- if (rc == -1) {
+ if (rc == -1)
goto exitagent;
- } else if (rc >= 0) {
+ if (rc >= 0)
nfs = rc;
- }
}
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_DISKS) {
rc = qemuAgentGetDisks(agent, &agentdiskinfo, report_unsupported);
- if (rc == -1) {
+ if (rc == -1)
goto exitagent;
- } else if (rc >= 0) {
+ if (rc >= 0)
ndisks = rc;
- }
}
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_INTERFACES) {
rc = qemuAgentGetInterfaces(agent, &ifaces, report_unsupported);
- if (rc == -1) {
+ if (rc == -1)
goto exitagent;
- } else if (rc >= 0) {
+ if (rc >= 0)
nifaces = rc;
- }
}
qemuDomainObjExitAgent(vm, agent);
--
2.31.1