From owner-svn-src-head@freebsd.org Wed Aug 5 07:33:40 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7B5423AD25B; Wed, 5 Aug 2020 07:33:40 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BM3Jh2dhRz4Spr; Wed, 5 Aug 2020 07:33:40 +0000 (UTC) (envelope-from mjg@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3E7CF12D06; Wed, 5 Aug 2020 07:33:40 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0757XeVS043344; Wed, 5 Aug 2020 07:33:40 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0757Xem6043343; Wed, 5 Aug 2020 07:33:40 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202008050733.0757Xem6043343@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 5 Aug 2020 07:33:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363885 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 363885 X-SVN-Commit-Repository: base 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.33 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: Wed, 05 Aug 2020 07:33:40 -0000 Author: mjg Date: Wed Aug 5 07:33:39 2020 New Revision: 363885 URL: https://svnweb.freebsd.org/changeset/base/363885 Log: vfs: tidy up namei entry point - predict for string copy errors - reshuffle inititalistion of vars which are not needed Modified: head/sys/kern/vfs_lookup.c Modified: head/sys/kern/vfs_lookup.c ============================================================================== --- head/sys/kern/vfs_lookup.c Wed Aug 5 07:32:26 2020 (r363884) +++ head/sys/kern/vfs_lookup.c Wed Aug 5 07:33:39 2020 (r363885) @@ -297,6 +297,7 @@ namei_setup(struct nameidata *ndp, struct vnode **dpp, startdir_used = false; *pwdp = NULL; + *dpp = NULL; #ifdef CAPABILITY_MODE /* @@ -470,7 +471,6 @@ namei(struct nameidata *ndp) struct iovec aiov; /* uio for reading symbolic links */ struct componentname *cnp; struct thread *td; - struct proc *p; struct pwd *pwd; struct uio auio; int error, linklen; @@ -478,23 +478,19 @@ namei(struct nameidata *ndp) cnp = &ndp->ni_cnd; td = cnp->cn_thread; - p = td->td_proc; ndp->ni_cnd.cn_cred = ndp->ni_cnd.cn_thread->td_ucred; - KASSERT(cnp->cn_cred && p, ("namei: bad cred/proc")); + KASSERT(cnp->cn_cred && td->td_proc, ("namei: bad cred/proc")); KASSERT((cnp->cn_nameiop & (~OPMASK)) == 0, ("namei: nameiop contaminated with flags")); KASSERT((cnp->cn_flags & OPMASK) == 0, ("namei: flags contaminated with nameiops")); MPASS(ndp->ni_startdir == NULL || ndp->ni_startdir->v_type == VDIR || ndp->ni_startdir->v_type == VBAD); - TAILQ_INIT(&ndp->ni_cap_tracker); - ndp->ni_lcf = 0; - ndp->ni_loopcnt = 0; - dp = NULL; /* We will set this ourselves if we need it. */ cnp->cn_flags &= ~TRAILINGSLASH; + ndp->ni_lcf = 0; ndp->ni_vp = NULL; /* @@ -510,17 +506,15 @@ namei(struct nameidata *ndp) error = copyinstr(ndp->ni_dirp, cnp->cn_pnbuf, MAXPATHLEN, &ndp->ni_pathlen); - if (error != 0) { + if (__predict_false(error != 0)) { namei_cleanup_cnp(cnp); return (error); } - cnp->cn_nameptr = cnp->cn_pnbuf; - /* * Don't allow empty pathnames. */ - if (*cnp->cn_pnbuf == '\0') { + if (__predict_false(*cnp->cn_pnbuf == '\0')) { namei_cleanup_cnp(cnp); return (ENOENT); } @@ -533,6 +527,8 @@ namei(struct nameidata *ndp) } #endif + cnp->cn_nameptr = cnp->cn_pnbuf; + /* * First try looking up the target without locking any vnodes. * @@ -546,9 +542,11 @@ namei(struct nameidata *ndp) case CACHE_FPL_STATUS_HANDLED: return (error); case CACHE_FPL_STATUS_PARTIAL: + TAILQ_INIT(&ndp->ni_cap_tracker); dp = ndp->ni_startdir; break; case CACHE_FPL_STATUS_ABORTED: + TAILQ_INIT(&ndp->ni_cap_tracker); error = namei_setup(ndp, &dp, &pwd); if (error != 0) { namei_cleanup_cnp(cnp); @@ -556,6 +554,8 @@ namei(struct nameidata *ndp) } break; } + + ndp->ni_loopcnt = 0; /* * Locked lookup.