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
* 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;
+ }
}
}