This patch rewrites the pattern using early return where it is
not needed.
Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
src/qemu/qemu_alias.c | 41 ++++++++++++++++-------------------------
1 file changed, 16 insertions(+), 25 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 5e35f43614..6f664fcd84 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -361,10 +361,9 @@ static int
qemuAssignDeviceSoundAlias(virDomainSoundDef *sound,
int idx)
{
- if (sound->info.alias)
- return 0;
+ if (!sound->info.alias)
+ sound->info.alias = g_strdup_printf("sound%d", idx);
- sound->info.alias = g_strdup_printf("sound%d", idx);
return 0;
}
@@ -373,10 +372,9 @@ static int
qemuAssignDeviceVideoAlias(virDomainVideoDef *video,
int idx)
{
- if (video->info.alias)
- return 0;
+ if (!video->info.alias)
+ video->info.alias = g_strdup_printf("video%d", idx);
- video->info.alias = g_strdup_printf("video%d", idx);
return 0;
}
@@ -385,10 +383,9 @@ static int
qemuAssignDeviceHubAlias(virDomainHubDef *hub,
int idx)
{
- if (hub->info.alias)
- return 0;
+ if (!hub->info.alias)
+ hub->info.alias = g_strdup_printf("hub%d", idx);
- hub->info.alias = g_strdup_printf("hub%d", idx);
return 0;
}
@@ -397,10 +394,9 @@ static int
qemuAssignDeviceSmartcardAlias(virDomainSmartcardDef *smartcard,
int idx)
{
- if (smartcard->info.alias)
- return 0;
+ if (!smartcard->info.alias)
+ smartcard->info.alias = g_strdup_printf("smartcard%d", idx);
- smartcard->info.alias = g_strdup_printf("smartcard%d", idx);
return 0;
}
@@ -409,10 +405,9 @@ static int
qemuAssignDeviceMemballoonAlias(virDomainMemballoonDef *memballoon,
int idx)
{
- if (memballoon->info.alias)
- return 0;
+ if (!memballoon->info.alias)
+ memballoon->info.alias = g_strdup_printf("balloon%d", idx);
- memballoon->info.alias = g_strdup_printf("balloon%d", idx);
return 0;
}
@@ -421,10 +416,9 @@ static int
qemuAssignDeviceTPMAlias(virDomainTPMDef *tpm,
int idx)
{
- if (tpm->info.alias)
- return 0;
+ if (!tpm->info.alias)
+ tpm->info.alias = g_strdup_printf("tpm%d", idx);
- tpm->info.alias = g_strdup_printf("tpm%d", idx);
return 0;
}
@@ -586,10 +580,8 @@ qemuAssignDeviceWatchdogAlias(virDomainWatchdogDef *watchdog)
{
/* Currently, there's just one watchdog per domain */
- if (watchdog->info.alias)
- return 0;
-
- watchdog->info.alias = g_strdup("watchdog0");
+ if (!watchdog->info.alias)
+ watchdog->info.alias = g_strdup("watchdog0");
return 0;
}
@@ -621,9 +613,8 @@ qemuAssignDeviceInputAlias(virDomainDef *def,
int
qemuAssignDeviceVsockAlias(virDomainVsockDef *vsock)
{
- if (vsock->info.alias)
- return 0;
- vsock->info.alias = g_strdup("vsock0");
+ if (!vsock->info.alias)
+ vsock->info.alias = g_strdup("vsock0");
return 0;
}
--
2.31.1