Refactor the logic to skip the body of the function if there's nothing to do. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_migration_cookie.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index 299bf17c9e..73ae815818 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -464,8 +464,13 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig, if (VIR_ALLOC(mig->nbd) < 0) return -1; - if (vm->def->ndisks && - VIR_ALLOC_N(mig->nbd->disks, vm->def->ndisks) < 0) + mig->nbd->port = priv->nbdPort; + mig->flags |= QEMU_MIGRATION_COOKIE_NBD; + + if (vm->def->ndisks == 0) + return 0; + + if (VIR_ALLOC_N(mig->nbd->disks, vm->def->ndisks) < 0) return -1; mig->nbd->ndisks = 0; @@ -496,9 +501,6 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig, mig->nbd->ndisks++; } - mig->nbd->port = priv->nbdPort; - mig->flags |= QEMU_MIGRATION_COOKIE_NBD; - ret = 0; cleanup: virHashFree(stats); -- 2.24.1