Index: sys/dev/iommu/iommu_gas.c =================================================================== --- sys/dev/iommu/iommu_gas.c +++ sys/dev/iommu/iommu_gas.c @@ -142,24 +142,35 @@ static void iommu_gas_augment_entry(struct iommu_map_entry *entry) { - struct iommu_map_entry *child; + struct iommu_map_entry *left, *right; iommu_gaddr_t free_down; + bool changed; - free_down = 0; - if ((child = RB_LEFT(entry, rb_entry)) != NULL) { - free_down = MAX(free_down, child->free_down); - free_down = MAX(free_down, entry->start - child->last); - entry->first = child->first; - } else + left = RB_LEFT(entry, rb_entry); + right = RB_RIGHT(entry, rb_entry); + if (left == NULL && right == NULL) { entry->first = entry->start; - - if ((child = RB_RIGHT(entry, rb_entry)) != NULL) { - free_down = MAX(free_down, child->free_down); - free_down = MAX(free_down, child->first - entry->end); - entry->last = child->last; - } else entry->last = entry->end; - entry->free_down = free_down; + entry->free_down = 0; + return; + } + if (left == NULL) { + entry->first = entry->start; + entry->last = right->last; + entry->free_down = right->first - entry->end; + return; + } + if (right == NULL) { + entry->first = left->start; + entry->last = entry->end; + entry->free_down = entry->start - left->last; + return; + } + entry->first = left->first; + entry->last = right->last; + entry->free_down = MAX( + MAX(left->free_down, entry->start - left->last), + MAX(right->free_down, right->first - entry->end)); } RB_GENERATE(iommu_gas_entries_tree, iommu_map_entry, rb_entry,