From 6fdbdafcd7b8551194a0505b6ad0154396b5953b Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Wed, 11 Nov 2015 15:18:07 +0100 Subject: [PATCH] domain-conf: cleanup controller insert function Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2edf12365d..f9fb68338b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13397,6 +13397,7 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def, int idx; /* Tenatively plan to insert controller at the end. */ int insertAt = -1; + virDomainControllerDefPtr current = NULL; /* Then work backwards looking for controllers of * the same type. If we find a controller with a @@ -13404,17 +13405,19 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def, * that position */ for (idx = (def->ncontrollers - 1); idx >= 0; idx--) { - /* If bus matches and current controller is after - * new controller, then new controller should go here */ - if (def->controllers[idx]->type == controller->type && - def->controllers[idx]->idx > controller->idx) { - insertAt = idx; - } else if (def->controllers[idx]->type == controller->type && - insertAt == -1) { - /* Last controller with match bus is before the - * new controller, then put new controller just after - */ - insertAt = idx + 1; + current = def->controllers[idx]; + if (current->type == controller->type) { + if (current->idx > controller->idx) { + /* If bus matches and current controller is after + * new controller, then new controller should go here + * */ + insertAt = idx; + } else if (insertAt == -1) { + /* Last controller with match bus is before the + * new controller, then put new controller just after + */ + insertAt = idx + 1; + } } } -- GitLab