From 4a1aec69b8c54ceaac717e92e810f38dfbf845f2 Mon Sep 17 00:00:00 2001 From: mjg Date: Sat, 31 Dec 2016 12:58:26 +0000 Subject: MFC r304927: vfs: provide a common exit point in namei for error cases This shortens the function, adds the SDT_PROBE use for error cases and consistenly unrefs rootdir last. --- sys/kern/vfs_lookup.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index c1ad31e..0fff629 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -380,9 +380,7 @@ namei(struct nameidata *ndp) if (error != 0) { if (dp != NULL) vrele(dp); - vrele(ndp->ni_rootdir); - namei_cleanup_cnp(cnp); - return (error); + goto out; } if ((ndp->ni_lcf & NI_LCF_STRICTRELATIVE) != 0 && lookup_cap_dotdot != 0) @@ -392,12 +390,8 @@ namei(struct nameidata *ndp) for (;;) { ndp->ni_startdir = dp; error = lookup(ndp); - if (error != 0) { - vrele(ndp->ni_rootdir); - namei_cleanup_cnp(cnp); - SDT_PROBE2(vfs, namei, lookup, return, error, NULL); - return (error); - } + if (error != 0) + goto out; /* * If not a symbolic link, we're done. */ @@ -471,18 +465,16 @@ namei(struct nameidata *ndp) if (*(cnp->cn_nameptr) == '/') { vrele(dp); error = namei_handle_root(ndp, &dp); - if (error != 0) { - vrele(ndp->ni_rootdir); - namei_cleanup_cnp(cnp); - return (error); - } + if (error != 0) + goto out; } } - vrele(ndp->ni_rootdir); - namei_cleanup_cnp(cnp); vput(ndp->ni_vp); ndp->ni_vp = NULL; vrele(ndp->ni_dvp); +out: + vrele(ndp->ni_rootdir); + namei_cleanup_cnp(cnp); nameicap_cleanup(ndp); SDT_PROBE2(vfs, namei, lookup, return, error, NULL); return (error); -- cgit v1.1