diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 46213feadf04..220d2868e712 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -1976,8 +1976,8 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, /* * Make a first pass to check for protection violations. */ - current = entry; - while ((current != &map->header) && (current->start < end)) { + for (current = entry; current != &map->header && current->start < end; + current = current->next) { if (current->eflags & MAP_ENTRY_IS_SUB_MAP) { vm_map_unlock(map); return (KERN_INVALID_ARGUMENT); @@ -1986,17 +1986,15 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_map_unlock(map); return (KERN_PROTECTION_FAILURE); } - current = current->next; } - /* * Do an accounting pass for private read-only mappings that * now will do cow due to allowed write (e.g. debugger sets * breakpoint on text segment) */ - for (current = entry; (current != &map->header) && - (current->start < end); current = current->next) { + for (current = entry; current != &map->header && current->start < end; + current = current->next) { vm_map_clip_end(map, current, end); @@ -2049,8 +2047,8 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, * Go back and fix up protections. [Note that clipping is not * necessary the second time.] */ - current = entry; - while ((current != &map->header) && (current->start < end)) { + for (current = entry; current != &map->header && current->start < end; + current = current->next) { old_prot = current->protection; if (set_max) @@ -2084,7 +2082,6 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, #undef MASK } vm_map_simplify_entry(map, current); - current = current->next; } vm_map_unlock(map); return (KERN_SUCCESS);