mnt = ERR_CAST(full_path);
                goto out;
        }
-
-       convert_delimiter(full_path, '/');
        cifs_dbg(FYI, "%s: full_path: %s\n", __func__, full_path);
 
        tmp = *cur_ctx;
 
                              cifs_remap(cifs_sb), path, ref, tl);
 }
 
+/* Return DFS full path out of a dentry set for automount */
 static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
        struct TCP_Server_Info *server = tcon->ses->server;
+       size_t len;
+       char *s;
 
        if (unlikely(!server->origin_fullpath))
                return ERR_PTR(-EREMOTE);
 
-       return __build_path_from_dentry_optional_prefix(dentry, page,
-                                                       server->origin_fullpath,
-                                                       strlen(server->origin_fullpath),
-                                                       true);
+       s = dentry_path_raw(dentry, page, PATH_MAX);
+       if (IS_ERR(s))
+               return s;
+       /* for root, we want "" */
+       if (!s[1])
+               s++;
+
+       len = strlen(server->origin_fullpath);
+       if (s < (char *)page + len)
+               return ERR_PTR(-ENAMETOOLONG);
+
+       s -= len;
+       memcpy(s, server->origin_fullpath, len);
+       convert_delimiter(s, '/');
+       return s;
 }
 
 static inline void dfs_put_root_smb_sessions(struct list_head *head)