From c3bb2b2d5d0098b556a88b696540f1a65641a7c2 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 7 Dec 2020 12:24:31 +0100 Subject: [PATCH] qemuDomainDiskLookupByNodename: Simplify node name lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use dummy variable to fill 'src' so that access to it doesn't need to be conditionalized and use temporary variable for 'disk' rather than dereferencing the array multiple times. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_domain.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f14a15d3b4..e4322aa2f6 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9910,24 +9910,18 @@ qemuDomainDiskLookupByNodename(virDomainDefPtr def, size_t i; virStorageSourcePtr tmp = NULL; - if (src) - *src = NULL; + if (!src) + src = &tmp; for (i = 0; i < def->ndisks; i++) { - if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src, nodename))) { - if (src) - *src = tmp; + virDomainDiskDefPtr domdisk = def->disks[i]; - return def->disks[i]; - } + if ((*src = virStorageSourceFindByNodeName(domdisk->src, nodename))) + return domdisk; - if (def->disks[i]->mirror && - (tmp = virStorageSourceFindByNodeName(def->disks[i]->mirror, nodename))) { - if (src) - *src = tmp; - - return def->disks[i]; - } + if (domdisk->mirror && + (*src = virStorageSourceFindByNodeName(domdisk->mirror, nodename))) + return domdisk; } return NULL;