f2fs: switch to fscrypt_get_symlink()
authorEric Biggers <ebiggers@google.com>
Fri, 12 Jan 2018 04:26:49 +0000 (23:26 -0500)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 8 Apr 2018 09:40:45 +0000 (02:40 -0700)
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/f2fs/namei.c

index a171405204b2b31322a2841dd7e6c6fefa3577d7..2ebf3d045dd279e3f869e7cb641ca8c1d030cc70 100644 (file)
@@ -1098,68 +1098,20 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,
                                           struct inode *inode,
                                           struct delayed_call *done)
 {
-       struct page *cpage = NULL;
-       char *caddr, *paddr = NULL;
-       struct fscrypt_str cstr = FSTR_INIT(NULL, 0);
-       struct fscrypt_str pstr = FSTR_INIT(NULL, 0);
-       struct fscrypt_symlink_data *sd;
-       u32 max_size = inode->i_sb->s_blocksize;
-       int res;
+       struct page *page;
+       const char *target;
 
        if (!dentry)
                return ERR_PTR(-ECHILD);
 
-       res = fscrypt_get_encryption_info(inode);
-       if (res)
-               return ERR_PTR(res);
-
-       cpage = read_mapping_page(inode->i_mapping, 0, NULL);
-       if (IS_ERR(cpage))
-               return ERR_CAST(cpage);
-       caddr = page_address(cpage);
-
-       /* Symlink is encrypted */
-       sd = (struct fscrypt_symlink_data *)caddr;
-       cstr.name = sd->encrypted_path;
-       cstr.len = le16_to_cpu(sd->len);
-
-       /* this is broken symlink case */
-       if (unlikely(cstr.len == 0)) {
-               res = -ENOENT;
-               goto errout;
-       }
-
-       if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) {
-               /* Symlink data on the disk is corrupted */
-               res = -EIO;
-               goto errout;
-       }
-       res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr);
-       if (res)
-               goto errout;
-
-       res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
-       if (res)
-               goto errout;
-
-       /* this is broken symlink case */
-       if (unlikely(pstr.name[0] == 0)) {
-               res = -ENOENT;
-               goto errout;
-       }
-
-       paddr = pstr.name;
-
-       /* Null-terminate the name */
-       paddr[pstr.len] = '\0';
+       page = read_mapping_page(inode->i_mapping, 0, NULL);
+       if (IS_ERR(page))
+               return ERR_CAST(page);
 
-       put_page(cpage);
-       set_delayed_call(done, kfree_link, paddr);
-       return paddr;
-errout:
-       fscrypt_fname_free_buffer(&pstr);
-       put_page(cpage);
-       return ERR_PTR(res);
+       target = fscrypt_get_symlink(inode, page_address(page),
+                                    inode->i_sb->s_blocksize, done);
+       put_page(page);
+       return target;
 }
 
 const struct inode_operations f2fs_encrypted_symlink_inode_operations = {