Index: sys/dev/iommu/iommu_gas.c =================================================================== --- sys/dev/iommu/iommu_gas.c +++ sys/dev/iommu/iommu_gas.c @@ -398,21 +398,12 @@ * requirements, or violates lowaddr address requirement. */ entry = first; - while (entry != NULL) { - if ((first = RB_LEFT(entry, rb_entry)) != NULL) { - if (first->last >= a->common->lowaddr) { - /* All remaining ranges >= lowaddr */ - break; - } - if (iommu_gas_match_one(a, first->last, entry->start, - a->common->lowaddr)) { - iommu_gas_match_insert(a); - return (0); - } - } - if (entry->end >= a->common->lowaddr) { - /* All remaining ranges >= lowaddr */ - break; + while (entry != NULL && entry->end < a->common->lowaddr) { + if ((first = RB_LEFT(entry, rb_entry)) != NULL && + iommu_gas_match_one(a, first->last, entry->start, + a->common->lowaddr)) { + iommu_gas_match_insert(a); + return (0); } if ((first = RB_RIGHT(entry, rb_entry)) != NULL && iommu_gas_match_one(a, entry->end, first->first, @@ -435,6 +426,16 @@ entry = first; } } + if (entry == NULL) + return (ENOMEM); + + if ((first = RB_LEFT(entry, rb_entry)) != NULL && + first->last < a->common->lowaddr && + iommu_gas_match_one(a, first->last, entry->start, + a->common->lowaddr)) { + iommu_gas_match_insert(a); + return (0); + } return (ENOMEM); }