From 85c4cddfb24427c468db621a5f23639bcb83a3ae Mon Sep 17 00:00:00 2001 From: alc Date: Sat, 18 Mar 2017 06:05:54 +0000 Subject: [PATCH] MFC r314717,315085 Style and punctuation fixes. Simplify the control flow and tidy up a comment in map_insert. --- sys/kern/imgact_elf.c | 87 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index e6fe4b0544f..70656efca4a 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -416,7 +416,7 @@ __elfN(map_partial)(vm_map_t map, vm_object_t object, vm_ooffset_t offset, /* * Find the page from the underlying object. */ - if (object) { + if (object != NULL) { sf = vm_imgact_map_page(object, offset); if (sf == NULL) return (KERN_FAILURE); @@ -444,7 +444,7 @@ __elfN(map_insert)(struct image_params *imgp, vm_map_t map, vm_object_t object, if (start != trunc_page(start)) { rv = __elfN(map_partial)(map, object, offset, start, round_page(start), prot); - if (rv) + if (rv != KERN_SUCCESS) return (rv); offset += round_page(start) - start; start = round_page(start); @@ -452,54 +452,51 @@ __elfN(map_insert)(struct image_params *imgp, vm_map_t map, vm_object_t object, if (end != round_page(end)) { rv = __elfN(map_partial)(map, object, offset + trunc_page(end) - start, trunc_page(end), end, prot); - if (rv) + if (rv != KERN_SUCCESS) return (rv); end = trunc_page(end); } - if (end > start) { - if (offset & PAGE_MASK) { - /* - * The mapping is not page aligned. This means we have - * to copy the data. Sigh. - */ - rv = vm_map_fixed(map, NULL, 0, start, end - start, - prot | VM_PROT_WRITE, VM_PROT_ALL, MAP_CHECK_EXCL); - if (rv != KERN_SUCCESS) - return (rv); - if (object == NULL) - return (KERN_SUCCESS); - for (; start < end; start += sz) { - sf = vm_imgact_map_page(object, offset); - if (sf == NULL) - return (KERN_FAILURE); - off = offset - trunc_page(offset); - sz = end - start; - if (sz > PAGE_SIZE - off) - sz = PAGE_SIZE - off; - error = copyout((caddr_t)sf_buf_kva(sf) + off, - (caddr_t)start, sz); - vm_imgact_unmap_page(sf); - if (error != 0) - return (KERN_FAILURE); - offset += sz; - } - rv = KERN_SUCCESS; - } else { - vm_object_reference(object); - rv = vm_map_fixed(map, object, offset, start, - end - start, prot, VM_PROT_ALL, - cow | MAP_CHECK_EXCL); - if (rv != KERN_SUCCESS) { - locked = VOP_ISLOCKED(imgp->vp); - VOP_UNLOCK(imgp->vp, 0); - vm_object_deallocate(object); - vn_lock(imgp->vp, locked | LK_RETRY); - } + if (start >= end) + return (KERN_SUCCESS); + if ((offset & PAGE_MASK) != 0) { + /* + * The mapping is not page aligned. This means that we have + * to copy the data. + */ + rv = vm_map_fixed(map, NULL, 0, start, end - start, + prot | VM_PROT_WRITE, VM_PROT_ALL, MAP_CHECK_EXCL); + if (rv != KERN_SUCCESS) + return (rv); + if (object == NULL) + return (KERN_SUCCESS); + for (; start < end; start += sz) { + sf = vm_imgact_map_page(object, offset); + if (sf == NULL) + return (KERN_FAILURE); + off = offset - trunc_page(offset); + sz = end - start; + if (sz > PAGE_SIZE - off) + sz = PAGE_SIZE - off; + error = copyout((caddr_t)sf_buf_kva(sf) + off, + (caddr_t)start, sz); + vm_imgact_unmap_page(sf); + if (error != 0) + return (KERN_FAILURE); + offset += sz; } - return (rv); } else { - return (KERN_SUCCESS); + vm_object_reference(object); + rv = vm_map_fixed(map, object, offset, start, end - start, + prot, VM_PROT_ALL, cow | MAP_CHECK_EXCL); + if (rv != KERN_SUCCESS) { + locked = VOP_ISLOCKED(imgp->vp); + VOP_UNLOCK(imgp->vp, 0); + vm_object_deallocate(object); + vn_lock(imgp->vp, locked | LK_RETRY); + return (rv); + } } + return (KERN_SUCCESS); } static int @@ -539,7 +536,7 @@ __elfN(load_section)(struct image_params *imgp, vm_ooffset_t offset, * We have two choices. We can either clear the data in the last page * of an oversized mapping, or we can start the anon mapping a page * early and copy the initialized data into that first page. We - * choose the second.. + * choose the second. */ if (memsz > filsz) map_len = trunc_page_ps(offset + filsz, pagesize) - file_addr; -- 2.45.0