struct cifs_sb_info *cifs_sb;
        struct cifs_ses *ses;
        struct cifs_tcon *tcon;
+       void *page;
        char *full_path, *root_path;
        unsigned int xid;
        int rc;
                goto cdda_exit;
        }
 
+       page = alloc_dentry_path();
        /* always use tree name prefix */
-       full_path = build_path_from_dentry_optional_prefix(mntpt, true);
-       if (full_path == NULL)
-               goto cdda_exit;
+       full_path = build_path_from_dentry_optional_prefix(mntpt, page, true);
+       if (IS_ERR(full_path)) {
+               mnt = ERR_CAST(full_path);
+               goto free_full_path;
+       }
 
        convert_delimiter(full_path, '\\');
 
 free_root_path:
        kfree(root_path);
 free_full_path:
-       kfree(full_path);
+       free_dentry_path(page);
 cdda_exit:
        cifs_dbg(FYI, "leaving %s\n" , __func__);
        return mnt;
 
 extern void exit_cifs_idmap(void);
 extern int init_cifs_spnego(void);
 extern void exit_cifs_spnego(void);
-extern const char *build_path_from_dentry(struct dentry *);
+extern const char *build_path_from_dentry(struct dentry *, void *);
 extern char *build_path_from_dentry_optional_prefix(struct dentry *direntry,
-                                                   bool prefix);
+                                                   void *page, bool prefix);
+static inline void *alloc_dentry_path(void)
+{
+       return __getname();
+}
+
+static inline void free_dentry_path(void *page)
+{
+       if (page)
+               __putname(page);
+}
+
 extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx,
                                     struct cifs_sb_info *cifs_sb,
                                     struct cifs_tcon *tcon,
 
 
 /* Note: caller must free return buffer */
 const char *
-build_path_from_dentry(struct dentry *direntry)
+build_path_from_dentry(struct dentry *direntry, void *page)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
        bool prefix = tcon->Flags & SMB_SHARE_IS_IN_DFS;
 
-       return build_path_from_dentry_optional_prefix(direntry,
+       return build_path_from_dentry_optional_prefix(direntry, page,
                                                      prefix);
 }
 
 char *
-build_path_from_dentry_optional_prefix(struct dentry *direntry, bool prefix)
+build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page,
+                                      bool prefix)
 {
        struct dentry *temp;
        int namelen;
        int dfsplen;
        int pplen = 0;
-       char *full_path;
+       char *full_path = page;
        char dirsep;
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
        unsigned seq;
 
+       if (unlikely(!page))
+               return ERR_PTR(-ENOMEM);
+
        dirsep = CIFS_DIR_SEP(cifs_sb);
        if (prefix)
                dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
        for (temp = direntry; !IS_ROOT(temp);) {
                namelen += (1 + temp->d_name.len);
                temp = temp->d_parent;
-               if (temp == NULL) {
-                       cifs_dbg(VFS, "corrupt dentry\n");
-                       rcu_read_unlock();
-                       return NULL;
-               }
        }
        rcu_read_unlock();
 
-       full_path = kmalloc(namelen+1, GFP_ATOMIC);
-       if (full_path == NULL)
-               return full_path;
+       if (namelen >= PAGE_SIZE)
+               return ERR_PTR(-ENAMETOOLONG);
+
        full_path[namelen] = 0; /* trailing null */
        rcu_read_lock();
        for (temp = direntry; !IS_ROOT(temp);) {
                }
                spin_unlock(&temp->d_lock);
                temp = temp->d_parent;
-               if (temp == NULL) {
-                       cifs_dbg(VFS, "corrupt dentry\n");
-                       rcu_read_unlock();
-                       kfree(full_path);
-                       return NULL;
-               }
        }
        rcu_read_unlock();
        if (namelen != dfsplen + pplen || read_seqretry(&rename_lock, seq)) {
                /* presumably this is only possible if racing with a rename
                of one of the parent directories  (we can not lock the dentries
                above us to prevent this, but retrying should be harmless) */
-               kfree(full_path);
                goto cifs_bp_rename_retry;
        }
        /* DIR_SEP already set for byte  0 / vs \ but not for
        int desired_access;
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifs_tcon *tcon = tlink_tcon(tlink);
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
        FILE_ALL_INFO *buf = NULL;
        struct inode *newinode = NULL;
        int disposition;
        if (tcon->ses->server->oplocks)
                *oplock = REQ_OPLOCK;
 
-       full_path = build_path_from_dentry(direntry);
-       if (!full_path)
-               return -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               free_dentry_path(page);
+               return PTR_ERR(full_path);
+       }
 
        if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
            (CIFS_UNIX_POSIX_PATH_OPS_CAP &
 
 out:
        kfree(buf);
-       kfree(full_path);
+       free_dentry_path(page);
        return rc;
 
 out_err:
        struct cifs_sb_info *cifs_sb;
        struct tcon_link *tlink;
        struct cifs_tcon *tcon;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page;
 
        if (!old_valid_dev(device_number))
                return -EINVAL;
        if (IS_ERR(tlink))
                return PTR_ERR(tlink);
 
+       page = alloc_dentry_path();
        tcon = tlink_tcon(tlink);
-
        xid = get_xid();
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto mknod_out;
        }
 
                                               device_number);
 
 mknod_out:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        struct tcon_link *tlink;
        struct cifs_tcon *pTcon;
        struct inode *newInode = NULL;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page;
 
        xid = get_xid();
 
        /* can not grab the rename sem here since it would
        deadlock in the cases (beginning of sys_rename itself)
        in which we already have the sb rename sem */
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
                cifs_put_tlink(tlink);
                free_xid(xid);
-               return ERR_PTR(-ENOMEM);
+               free_dentry_path(page);
+               return ERR_CAST(full_path);
        }
 
        if (d_really_is_positive(direntry)) {
                }
                newInode = ERR_PTR(rc);
        }
-       kfree(full_path);
+       free_dentry_path(page);
        cifs_put_tlink(tlink);
        free_xid(xid);
        return d_splice_alias(newInode, direntry);
 
        struct cifs_tcon *tcon;
        struct tcon_link *tlink;
        struct cifsFileInfo *cfile = NULL;
-       const char *full_path = NULL;
+       void *page;
+       const char *full_path;
        bool posix_open_ok = false;
        struct cifs_fid fid;
        struct cifs_pending_open open;
        tcon = tlink_tcon(tlink);
        server = tcon->ses->server;
 
-       full_path = build_path_from_dentry(file_dentry(file));
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(file_dentry(file), page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto out;
        }
 
        }
 
 out:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        struct TCP_Server_Info *server;
        struct cifsInodeInfo *cinode;
        struct inode *inode;
-       const char *full_path = NULL;
+       void *page;
+       const char *full_path;
        int desired_access;
        int disposition = FILE_OPEN;
        int create_options = CREATE_NOT_DIR;
        mutex_lock(&cfile->fh_mutex);
        if (!cfile->invalidHandle) {
                mutex_unlock(&cfile->fh_mutex);
-               rc = 0;
                free_xid(xid);
-               return rc;
+               return 0;
        }
 
        inode = d_inode(cfile->dentry);
         * called and if the server was down that means we end up here, and we
         * can never tell if the caller already has the rename_sem.
         */
-       full_path = build_path_from_dentry(cfile->dentry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(cfile->dentry, page);
+       if (IS_ERR(full_path)) {
                mutex_unlock(&cfile->fh_mutex);
+               free_dentry_path(page);
                free_xid(xid);
-               return rc;
+               return PTR_ERR(full_path);
        }
 
        cifs_dbg(FYI, "inode = 0x%p file flags 0x%x for %s\n",
                cifs_relock_file(cfile);
 
 reopen_error_exit:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        return rc;
 }
                       int flags,
                       struct cifsFileInfo **ret_file)
 {
-       struct list_head *tmp;
        struct cifsFileInfo *cfile;
-       struct cifsInodeInfo *cinode;
-       const char *full_path;
+       void *page = alloc_dentry_path();
 
        *ret_file = NULL;
 
        spin_lock(&tcon->open_file_lock);
-       list_for_each(tmp, &tcon->openFileList) {
-               cfile = list_entry(tmp, struct cifsFileInfo,
-                            tlist);
-               full_path = build_path_from_dentry(cfile->dentry);
-               if (full_path == NULL) {
+       list_for_each_entry(cfile, &tcon->openFileList, tlist) {
+               struct cifsInodeInfo *cinode;
+               const char *full_path = build_path_from_dentry(cfile->dentry, page);
+               if (IS_ERR(full_path)) {
                        spin_unlock(&tcon->open_file_lock);
-                       return -ENOMEM;
+                       free_dentry_path(page);
+                       return PTR_ERR(full_path);
                }
-               if (strcmp(full_path, name)) {
-                       kfree(full_path);
+               if (strcmp(full_path, name))
                        continue;
-               }
 
-               kfree(full_path);
                cinode = CIFS_I(d_inode(cfile->dentry));
                spin_unlock(&tcon->open_file_lock);
+               free_dentry_path(page);
                return cifs_get_writable_file(cinode, flags, ret_file);
        }
 
        spin_unlock(&tcon->open_file_lock);
+       free_dentry_path(page);
        return -ENOENT;
 }
 
 cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
                       struct cifsFileInfo **ret_file)
 {
-       struct list_head *tmp;
        struct cifsFileInfo *cfile;
-       struct cifsInodeInfo *cinode;
-       const char *full_path;
+       void *page = alloc_dentry_path();
 
        *ret_file = NULL;
 
        spin_lock(&tcon->open_file_lock);
-       list_for_each(tmp, &tcon->openFileList) {
-               cfile = list_entry(tmp, struct cifsFileInfo,
-                            tlist);
-               full_path = build_path_from_dentry(cfile->dentry);
-               if (full_path == NULL) {
+       list_for_each_entry(cfile, &tcon->openFileList, tlist) {
+               struct cifsInodeInfo *cinode;
+               const char *full_path = build_path_from_dentry(cfile->dentry, page);
+               if (IS_ERR(full_path)) {
                        spin_unlock(&tcon->open_file_lock);
-                       return -ENOMEM;
+                       free_dentry_path(page);
+                       return PTR_ERR(full_path);
                }
-               if (strcmp(full_path, name)) {
-                       kfree(full_path);
+               if (strcmp(full_path, name))
                        continue;
-               }
 
-               kfree(full_path);
                cinode = CIFS_I(d_inode(cfile->dentry));
                spin_unlock(&tcon->open_file_lock);
+               free_dentry_path(page);
                *ret_file = find_readable_file(cinode, 0);
                return *ret_file ? 0 : -ENOENT;
        }
 
        spin_unlock(&tcon->open_file_lock);
+       free_dentry_path(page);
        return -ENOENT;
 }
 
 
 {
        int rc = 0;
        unsigned int xid;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page;
        struct inode *inode = d_inode(dentry);
        struct cifsInodeInfo *cifs_inode;
        struct super_block *sb = dir->i_sb;
        server = tcon->ses->server;
 
        xid = get_xid();
+       page = alloc_dentry_path();
 
        if (tcon->nodelete) {
                rc = -EACCES;
 
        /* Unlink can be called from rename so we can not take the
         * sb->s_vfs_rename_mutex here */
-       full_path = build_path_from_dentry(dentry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto unlink_out;
        }
 
        cifs_inode = CIFS_I(dir);
        CIFS_I(dir)->time = 0;  /* force revalidate of dir as well */
 unlink_out:
-       kfree(full_path);
+       free_dentry_path(page);
        kfree(attrs);
        free_xid(xid);
        cifs_put_tlink(tlink);
        struct cifs_tcon *tcon;
        struct TCP_Server_Info *server;
        const char *full_path;
+       void *page;
 
        cifs_dbg(FYI, "In cifs_mkdir, mode = %04ho inode = 0x%p\n",
                 mode, inode);
 
        xid = get_xid();
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto mkdir_out;
        }
 
         * attributes are invalid now.
         */
        CIFS_I(inode)->time = 0;
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        struct tcon_link *tlink;
        struct cifs_tcon *tcon;
        struct TCP_Server_Info *server;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
        struct cifsInodeInfo *cifsInode;
 
        cifs_dbg(FYI, "cifs_rmdir, inode = 0x%p\n", inode);
 
        xid = get_xid();
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto rmdir_exit;
        }
 
                current_time(inode);
 
 rmdir_exit:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        return rc;
 }
             struct dentry *source_dentry, struct inode *target_dir,
             struct dentry *target_dentry, unsigned int flags)
 {
-       const char *from_name = NULL;
-       const char *to_name = NULL;
+       const char *from_name, *to_name;
+       void *page1, *page2;
        struct cifs_sb_info *cifs_sb;
        struct tcon_link *tlink;
        struct cifs_tcon *tcon;
                return PTR_ERR(tlink);
        tcon = tlink_tcon(tlink);
 
+       page1 = alloc_dentry_path();
+       page2 = alloc_dentry_path();
        xid = get_xid();
 
-       /*
-        * we already have the rename sem so we do not need to
-        * grab it again here to protect the path integrity
-        */
-       from_name = build_path_from_dentry(source_dentry);
-       if (from_name == NULL) {
-               rc = -ENOMEM;
+       from_name = build_path_from_dentry(source_dentry, page1);
+       if (IS_ERR(from_name)) {
+               rc = PTR_ERR(from_name);
                goto cifs_rename_exit;
        }
 
-       to_name = build_path_from_dentry(target_dentry);
-       if (to_name == NULL) {
-               rc = -ENOMEM;
+       to_name = build_path_from_dentry(target_dentry, page2);
+       if (IS_ERR(to_name)) {
+               rc = PTR_ERR(to_name);
                goto cifs_rename_exit;
        }
 
 
 cifs_rename_exit:
        kfree(info_buf_source);
-       kfree(from_name);
-       kfree(to_name);
+       free_dentry_path(page2);
+       free_dentry_path(page1);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        int rc = 0;
        struct inode *inode = d_inode(dentry);
        struct super_block *sb = dentry->d_sb;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page;
        int count = 0;
 
        if (inode == NULL)
 
        xid = get_xid();
 
-       /* can not safely grab the rename sem here if rename calls revalidate
-          since that would deadlock */
-       full_path = build_path_from_dentry(dentry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto out;
        }
 
        if (rc == -EAGAIN && count++ < 10)
                goto again;
 out:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
 
        return rc;
 {
        int rc;
        unsigned int xid;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
        struct inode *inode = d_inode(direntry);
        struct cifsInodeInfo *cifsInode = CIFS_I(inode);
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        if (rc < 0)
                goto out;
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto out;
        }
 
                cifsInode->time = 0;
 out:
        kfree(args);
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        return rc;
 }
        struct cifsInodeInfo *cifsInode = CIFS_I(inode);
        struct cifsFileInfo *wfile;
        struct cifs_tcon *tcon;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
        int rc = -EACCES;
        __u32 dosattr = 0;
        __u64 mode = NO_CHANGE_64;
                attrs->ia_valid |= ATTR_FORCE;
 
        rc = setattr_prepare(&init_user_ns, direntry, attrs);
-       if (rc < 0) {
-               free_xid(xid);
-               return rc;
-       }
+       if (rc < 0)
+               goto cifs_setattr_exit;
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
-               free_xid(xid);
-               return rc;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
+               goto cifs_setattr_exit;
        }
 
        /*
        mark_inode_dirty(inode);
 
 cifs_setattr_exit:
-       kfree(full_path);
        free_xid(xid);
+       free_dentry_path(page);
        return rc;
 }
 
 
        struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
        struct dentry *dentry = filep->f_path.dentry;
        const unsigned char *path;
+       void *page = alloc_dentry_path();
        __le16 *utf16_path = NULL, root_path;
        int rc = 0;
 
-       path = build_path_from_dentry(dentry);
-       if (path == NULL)
-               return -ENOMEM;
+       path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(path)) {
+               free_dentry_path(page);
+               return PTR_ERR(path);
+       }
 
        cifs_dbg(FYI, "%s %s\n", __func__, path);
 
  ici_exit:
        if (utf16_path != &root_path)
                kfree(utf16_path);
-       kfree(path);
+       free_dentry_path(page);
        return rc;
 }
 
 
 {
        int rc = -EACCES;
        unsigned int xid;
-       const char *from_name = NULL;
-       const char *to_name = NULL;
+       const char *from_name, *to_name;
+       void *page1, *page2;
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct tcon_link *tlink;
        struct cifs_tcon *tcon;
        tcon = tlink_tcon(tlink);
 
        xid = get_xid();
+       page1 = alloc_dentry_path();
+       page2 = alloc_dentry_path();
 
-       from_name = build_path_from_dentry(old_file);
-       to_name = build_path_from_dentry(direntry);
-       if ((from_name == NULL) || (to_name == NULL)) {
-               rc = -ENOMEM;
+       from_name = build_path_from_dentry(old_file, page1);
+       if (IS_ERR(from_name)) {
+               rc = PTR_ERR(from_name);
+               goto cifs_hl_exit;
+       }
+       to_name = build_path_from_dentry(direntry, page2);
+       if (IS_ERR(to_name)) {
+               rc = PTR_ERR(to_name);
                goto cifs_hl_exit;
        }
 
        }
 
 cifs_hl_exit:
-       kfree(from_name);
-       kfree(to_name);
+       free_dentry_path(page1);
+       free_dentry_path(page2);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
 {
        int rc = -ENOMEM;
        unsigned int xid;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page;
        char *target_path = NULL;
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct tcon_link *tlink = NULL;
        tcon = tlink_tcon(tlink);
        server = tcon->ses->server;
 
-       full_path = build_path_from_dentry(direntry);
-       if (!full_path) {
+       page = alloc_dentry_path();
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
                free_xid(xid);
                cifs_put_tlink(tlink);
-               return ERR_PTR(-ENOMEM);
+               free_dentry_path(page);
+               return ERR_CAST(full_path);
        }
 
        cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", full_path, inode);
                                                &target_path, reparse_point);
        }
 
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        if (rc != 0) {
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct tcon_link *tlink;
        struct cifs_tcon *pTcon;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
        struct inode *newinode = NULL;
 
        xid = get_xid();
        }
        pTcon = tlink_tcon(tlink);
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto symlink_exit;
        }
 
                }
        }
 symlink_exit:
-       kfree(full_path);
+       free_dentry_path(page);
        cifs_put_tlink(tlink);
        free_xid(xid);
        return rc;
 
        char *tmp_buf = NULL;
        char *end_of_smb;
        unsigned int max_len;
-       const char *full_path = NULL;
+       const char *full_path;
+       void *page = alloc_dentry_path();
 
        xid = get_xid();
 
-       full_path = build_path_from_dentry(file_dentry(file));
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(file_dentry(file), page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto rddir2_exit;
        }
 
        kfree(tmp_buf);
 
 rddir2_exit:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        return rc;
 }
 
        struct smb3_notify notify;
        struct dentry *dentry = pfile->f_path.dentry;
        struct inode *inode = file_inode(pfile);
-       struct cifs_sb_info *cifs_sb;
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifs_open_parms oparms;
        struct cifs_fid fid;
        struct cifs_tcon *tcon;
-       const unsigned char *path = NULL;
+       const unsigned char *path;
+       void *page = alloc_dentry_path();
        __le16 *utf16_path = NULL;
        u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
        int rc = 0;
 
-       path = build_path_from_dentry(dentry);
-       if (path == NULL)
-               return -ENOMEM;
-
-       cifs_sb = CIFS_SB(inode->i_sb);
+       path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(path)) {
+               rc = PTR_ERR(path);
+               goto notify_exit;
+       }
 
        utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
        if (utf16_path == NULL) {
        cifs_dbg(FYI, "change notify for path %s rc %d\n", path, rc);
 
 notify_exit:
-       kfree(path);
+       free_dentry_path(page);
        kfree(utf16_path);
        return rc;
 }
 
        struct tcon_link *tlink;
        struct cifs_tcon *pTcon;
        const char *full_path;
+       void *page;
 
        tlink = cifs_sb_tlink(cifs_sb);
        if (IS_ERR(tlink))
        pTcon = tlink_tcon(tlink);
 
        xid = get_xid();
+       page = alloc_dentry_path();
 
-       full_path = build_path_from_dentry(dentry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto out;
        }
        /* return dos attributes as pseudo xattr */
        }
 
 out:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        struct tcon_link *tlink;
        struct cifs_tcon *pTcon;
        const char *full_path;
+       void *page;
 
        tlink = cifs_sb_tlink(cifs_sb);
        if (IS_ERR(tlink))
        pTcon = tlink_tcon(tlink);
 
        xid = get_xid();
+       page = alloc_dentry_path();
 
-       full_path = build_path_from_dentry(dentry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(dentry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto out;
        }
 
                rc = -EOPNOTSUPP;
 
 out:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;
        struct tcon_link *tlink;
        struct cifs_tcon *pTcon;
        const char *full_path;
+       void *page;
 
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
                return -EOPNOTSUPP;
        pTcon = tlink_tcon(tlink);
 
        xid = get_xid();
+       page = alloc_dentry_path();
 
-       full_path = build_path_from_dentry(direntry);
-       if (full_path == NULL) {
-               rc = -ENOMEM;
+       full_path = build_path_from_dentry(direntry, page);
+       if (IS_ERR(full_path)) {
+               rc = PTR_ERR(full_path);
                goto list_ea_exit;
        }
        /* return dos attributes as pseudo xattr */
                rc = pTcon->ses->server->ops->query_all_EAs(xid, pTcon,
                                full_path, NULL, data, buf_size, cifs_sb);
 list_ea_exit:
-       kfree(full_path);
+       free_dentry_path(page);
        free_xid(xid);
        cifs_put_tlink(tlink);
        return rc;