* to restart the path walk from the beginning in ref-walk mode.
  */
 
+static void terminate_walk(struct nameidata *nd);
+
 /**
  * unlazy_walk - try to switch to ref-walk mode.
  * @nd: nameidata pathwalk data
        int status;
 
        if (nd->flags & LOOKUP_RCU) {
-               nd->flags &= ~LOOKUP_RCU;
                if (!(nd->flags & LOOKUP_ROOT))
                        nd->root.mnt = NULL;
-
-               if (!legitimize_mnt(nd->path.mnt, nd->m_seq)) {
-                       rcu_read_unlock();
-                       return -ECHILD;
-               }
-               if (unlikely(!lockref_get_not_dead(&dentry->d_lockref))) {
-                       rcu_read_unlock();
-                       mntput(nd->path.mnt);
-                       return -ECHILD;
-               }
-               if (read_seqcount_retry(&dentry->d_seq, nd->seq)) {
-                       rcu_read_unlock();
-                       dput(dentry);
-                       mntput(nd->path.mnt);
+               if (unlikely(unlazy_walk(nd, NULL))) {
+                       terminate_walk(nd);
                        return -ECHILD;
                }
-               rcu_read_unlock();
        }
 
        if (likely(!(nd->flags & LOOKUP_JUMPED)))
        if (!status)
                status = -ESTALE;
 
-       path_put(&nd->path);
+       terminate_walk(nd);
        return status;
 }
 
                 * about to look up
                 */
                error = complete_walk(nd);
-               if (error) {
-                       if (nd->depth)
-                               put_link(nd);
+               if (error)
                        return error;
-               }
 
                audit_inode(name, dir, LOOKUP_PARENT);
                error = -EISDIR;
 finish_open:
        error = complete_walk(nd);
        if (error) {
-               if (nd->depth)
-                       put_link(nd);
                path_put(&save_parent);
                return error;
        }