add patch fix-ocfs2-corrupt-when-updating-journal-superblock-fails
[ext4-patch-queue.git] / crypto-get-rid-of-ci_mode
blobd744898d1f7e5b024173cc83d0364e6dd2404f52
1 ext4 crypto: get rid of ci_mode from struct ext4_crypt_info
3 The ci_mode field was superfluous, and getting rid of it gets rid of
4 an unused hole in the structure.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/ext4/crypto.c       | 11 +++++------
9  fs/ext4/crypto_fname.c |  4 ++--
10  fs/ext4/crypto_key.c   | 11 +++++------
11  fs/ext4/ext4_crypto.h  |  1 -
12  4 files changed, 12 insertions(+), 15 deletions(-)
14 diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
15 index 1c34f0e..9969d05 100644
16 --- a/fs/ext4/crypto.c
17 +++ b/fs/ext4/crypto.c
18 @@ -137,14 +137,13 @@ struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode)
20         /* Allocate a new Crypto API context if we don't already have
21          * one or if it isn't the right mode. */
22 -       BUG_ON(ci->ci_mode == EXT4_ENCRYPTION_MODE_INVALID);
23 -       if (ctx->tfm && (ctx->mode != ci->ci_mode)) {
24 +       if (ctx->tfm && (ctx->mode != ci->ci_data_mode)) {
25                 crypto_free_tfm(ctx->tfm);
26                 ctx->tfm = NULL;
27                 ctx->mode = EXT4_ENCRYPTION_MODE_INVALID;
28         }
29         if (!ctx->tfm) {
30 -               switch (ci->ci_mode) {
31 +               switch (ci->ci_data_mode) {
32                 case EXT4_ENCRYPTION_MODE_AES_256_XTS:
33                         ctx->tfm = crypto_ablkcipher_tfm(
34                                 crypto_alloc_ablkcipher("xts(aes)", 0, 0));
35 @@ -162,9 +161,9 @@ struct ext4_crypto_ctx *ext4_get_crypto_ctx(struct inode *inode)
36                         ctx->tfm = NULL;
37                         goto out;
38                 }
39 -               ctx->mode = ci->ci_mode;
40 +               ctx->mode = ci->ci_data_mode;
41         }
42 -       BUG_ON(ci->ci_size != ext4_encryption_key_size(ci->ci_mode));
43 +       BUG_ON(ci->ci_size != ext4_encryption_key_size(ci->ci_data_mode));
45         /* There shouldn't be a bounce page attached to the crypto
46          * context at this point. */
47 @@ -321,7 +320,7 @@ static int ext4_page_crypto(struct ext4_crypto_ctx *ctx,
48         int res = 0;
50         BUG_ON(!ctx->tfm);
51 -       BUG_ON(ctx->mode != ei->i_crypt_info->ci_mode);
52 +       BUG_ON(ctx->mode != ei->i_crypt_info->ci_data_mode);
54         if (ctx->mode != EXT4_ENCRYPTION_MODE_AES_256_XTS) {
55                 printk_ratelimited(KERN_ERR
56 diff --git a/fs/ext4/crypto_fname.c b/fs/ext4/crypto_fname.c
57 index 374d0e7..e63dd29 100644
58 --- a/fs/ext4/crypto_fname.c
59 +++ b/fs/ext4/crypto_fname.c
60 @@ -272,9 +272,9 @@ int ext4_setup_fname_crypto(struct inode *inode)
61         if (!ci || ci->ci_ctfm)
62                 return 0;
64 -       if (ci->ci_mode != EXT4_ENCRYPTION_MODE_AES_256_CTS) {
65 +       if (ci->ci_filename_mode != EXT4_ENCRYPTION_MODE_AES_256_CTS) {
66                 printk_once(KERN_WARNING "ext4: unsupported key mode %d\n",
67 -                           ci->ci_mode);
68 +                           ci->ci_filename_mode);
69                 return -ENOKEY;
70         }
72 diff --git a/fs/ext4/crypto_key.c b/fs/ext4/crypto_key.c
73 index d6abe46..858d7d6 100644
74 --- a/fs/ext4/crypto_key.c
75 +++ b/fs/ext4/crypto_key.c
76 @@ -152,14 +152,13 @@ int _ext4_get_encryption_info(struct inode *inode)
77         memcpy(crypt_info->ci_master_key, ctx.master_key_descriptor,
78                sizeof(crypt_info->ci_master_key));
79         if (S_ISREG(inode->i_mode))
80 -               crypt_info->ci_mode = ctx.contents_encryption_mode;
81 +               crypt_info->ci_size =
82 +                       ext4_encryption_key_size(crypt_info->ci_data_mode);
83         else if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
84 -               crypt_info->ci_mode = ctx.filenames_encryption_mode;
85 -       else {
86 -               printk(KERN_ERR "ext4 crypto: Unsupported inode type.\n");
87 +               crypt_info->ci_size =
88 +                       ext4_encryption_key_size(crypt_info->ci_filename_mode);
89 +       else
90                 BUG();
91 -       }
92 -       crypt_info->ci_size = ext4_encryption_key_size(crypt_info->ci_mode);
93         BUG_ON(!crypt_info->ci_size);
94         if (DUMMY_ENCRYPTION_ENABLED(sbi)) {
95                 memset(crypt_info->ci_raw, 0x42, EXT4_AES_256_XTS_KEY_SIZE);
96 diff --git a/fs/ext4/ext4_crypto.h b/fs/ext4/ext4_crypto.h
97 index d29687c..69faf0e 100644
98 --- a/fs/ext4/ext4_crypto.h
99 +++ b/fs/ext4/ext4_crypto.h
100 @@ -74,7 +74,6 @@ struct ext4_encryption_key {
101  } __attribute__((__packed__));
103  struct ext4_crypt_info {
104 -       unsigned char   ci_mode;
105         unsigned char   ci_size;
106         char            ci_data_mode;
107         char            ci_filename_mode;