From owner-svn-src-head@freebsd.org Sat Mar 11 18:57:14 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B664AD06F40; Sat, 11 Mar 2017 18:57:14 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 749A21CF7; Sat, 11 Mar 2017 18:57:14 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2BIvDKS003141; Sat, 11 Mar 2017 18:57:13 GMT (envelope-from alc@FreeBSD.org) Received: (from alc@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2BIvDed003140; Sat, 11 Mar 2017 18:57:13 GMT (envelope-from alc@FreeBSD.org) Message-Id: <201703111857.v2BIvDed003140@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alc set sender to alc@FreeBSD.org using -f From: Alan Cox Date: Sat, 11 Mar 2017 18:57:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315085 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Mar 2017 18:57:14 -0000 Author: alc Date: Sat Mar 11 18:57:13 2017 New Revision: 315085 URL: https://svnweb.freebsd.org/changeset/base/315085 Log: Simplify the control flow and tidy up a comment in map_insert. In collaboration with: kib MFC after: 1 week Modified: head/sys/kern/imgact_elf.c Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Sat Mar 11 18:46:46 2017 (r315084) +++ head/sys/kern/imgact_elf.c Sat Mar 11 18:57:13 2017 (r315085) @@ -456,50 +456,47 @@ __elfN(map_insert)(struct image_params * 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