aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2016-09-15 17:25:55 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-09-15 17:25:55 -0400
commitef1eb3aa50930f026135085cd160b1212cdfe817 (patch)
tree12ed99fd9e7dc658b0e1bb0bc78e2ad0bb887dca /fs/f2fs
parent53fd7550ec40571e26f730a0d3fc0a5dd93ecda2 (diff)
fscrypto: make filename crypto functions return 0 on success
Several filename crypto functions: fname_decrypt(), fscrypt_fname_disk_to_usr(), and fscrypt_fname_usr_to_disk(), returned the output length on success or -errno on failure. However, the output length was redundant with the value written to 'oname->len'. It is also potentially error-prone to make callers have to check for '< 0' instead of '!= 0'. Therefore, make these functions return 0 instead of a length, and make the callers who cared about the return value being a length use 'oname->len' instead. For consistency also make other callers check for a nonzero result rather than a negative result. This change also fixes the inconsistency of fname_encrypt() actually already returning 0 on success, not a length like the other filename crypto functions and as documented in its function comment. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Andreas Dilger <adilger@dilger.ca> Acked-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs')
-rw-r--r--fs/f2fs/dir.c6
-rw-r--r--fs/f2fs/namei.c6
2 files changed, 6 insertions, 6 deletions
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 9054aeac8015..8716943335b1 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -786,7 +786,7 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
786 786
787 if (f2fs_encrypted_inode(d->inode)) { 787 if (f2fs_encrypted_inode(d->inode)) {
788 int save_len = fstr->len; 788 int save_len = fstr->len;
789 int ret; 789 int err;
790 790
791 de_name.name = f2fs_kmalloc(de_name.len, GFP_NOFS); 791 de_name.name = f2fs_kmalloc(de_name.len, GFP_NOFS);
792 if (!de_name.name) 792 if (!de_name.name)
@@ -794,11 +794,11 @@ bool f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
794 794
795 memcpy(de_name.name, d->filename[bit_pos], de_name.len); 795 memcpy(de_name.name, d->filename[bit_pos], de_name.len);
796 796
797 ret = fscrypt_fname_disk_to_usr(d->inode, 797 err = fscrypt_fname_disk_to_usr(d->inode,
798 (u32)de->hash_code, 0, 798 (u32)de->hash_code, 0,
799 &de_name, fstr); 799 &de_name, fstr);
800 kfree(de_name.name); 800 kfree(de_name.name);
801 if (ret < 0) 801 if (err)
802 return true; 802 return true;
803 803
804 de_name = *fstr; 804 de_name = *fstr;
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 73fa356f8fbb..afd56332d34c 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -449,7 +449,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
449 ostr.name = sd->encrypted_path; 449 ostr.name = sd->encrypted_path;
450 ostr.len = disk_link.len; 450 ostr.len = disk_link.len;
451 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); 451 err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr);
452 if (err < 0) 452 if (err)
453 goto err_out; 453 goto err_out;
454 454
455 sd->len = cpu_to_le16(ostr.len); 455 sd->len = cpu_to_le16(ostr.len);
@@ -1048,7 +1048,7 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,
1048 goto errout; 1048 goto errout;
1049 1049
1050 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); 1050 res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr);
1051 if (res < 0) 1051 if (res)
1052 goto errout; 1052 goto errout;
1053 1053
1054 /* this is broken symlink case */ 1054 /* this is broken symlink case */
@@ -1060,7 +1060,7 @@ static const char *f2fs_encrypted_get_link(struct dentry *dentry,
1060 paddr = pstr.name; 1060 paddr = pstr.name;
1061 1061
1062 /* Null-terminate the name */ 1062 /* Null-terminate the name */
1063 paddr[res] = '\0'; 1063 paddr[pstr.len] = '\0';
1064 1064
1065 put_page(cpage); 1065 put_page(cpage);
1066 set_delayed_call(done, kfree_link, paddr); 1066 set_delayed_call(done, kfree_link, paddr);