Add stable@vger.kernel.org annotations
[ext4-patch-queue.git] / use-standard-macros-to-compute-length-of-fname-ciphertext
blob1eafdecbdf089b3ed1a93510d7793a36b3b313c9
1 fscrypto: use standard macros to compute length of fname ciphertext
3 From: Eric Biggers <ebiggers@google.com>
5 Signed-off-by: Eric Biggers <ebiggers@google.com>
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/crypto/fname.c | 17 +++++------------
9  1 file changed, 5 insertions(+), 12 deletions(-)
11 diff --git a/fs/crypto/fname.c b/fs/crypto/fname.c
12 index 90697c7..9a28133 100644
13 --- a/fs/crypto/fname.c
14 +++ b/fs/crypto/fname.c
15 @@ -14,11 +14,6 @@
16  #include <linux/ratelimit.h>
17  #include <linux/fscrypto.h>
19 -static u32 size_round_up(size_t size, size_t blksize)
21 -       return ((size + blksize - 1) / blksize) * blksize;
24  /**
25   * fname_crypt_complete() - completion callback for filename crypto
26   * @req: The asynchronous cipher request context
27 @@ -60,10 +55,9 @@ static int fname_encrypt(struct inode *inode,
28         if (iname->len <= 0 || iname->len > lim)
29                 return -EIO;
31 -       ciphertext_len = (iname->len < FS_CRYPTO_BLOCK_SIZE) ?
32 -                                       FS_CRYPTO_BLOCK_SIZE : iname->len;
33 -       ciphertext_len = size_round_up(ciphertext_len, padding);
34 -       ciphertext_len = (ciphertext_len > lim) ? lim : ciphertext_len;
35 +       ciphertext_len = max(iname->len, (u32)FS_CRYPTO_BLOCK_SIZE);
36 +       ciphertext_len = round_up(ciphertext_len, padding);
37 +       ciphertext_len = min(ciphertext_len, lim);
39         if (ciphertext_len <= sizeof(buf)) {
40                 workbuf = buf;
41 @@ -233,9 +227,8 @@ u32 fscrypt_fname_encrypted_size(struct inode *inode, u32 ilen)
43         if (ci)
44                 padding = 4 << (ci->ci_flags & FS_POLICY_FLAGS_PAD_MASK);
45 -       if (ilen < FS_CRYPTO_BLOCK_SIZE)
46 -               ilen = FS_CRYPTO_BLOCK_SIZE;
47 -       return size_round_up(ilen, padding);
48 +       ilen = max(ilen, (u32)FS_CRYPTO_BLOCK_SIZE);
49 +       return round_up(ilen, padding);
50  }
51  EXPORT_SYMBOL(fscrypt_fname_encrypted_size);
53 -- 
54 2.8.0.rc3.226.g39d4020
57 To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
58 the body of a message to majordomo@vger.kernel.org
59 More majordomo info at  http://vger.kernel.org/majordomo-info.html