Commit cd0265fc authored by Eric Biggers's avatar Eric Biggers Committed by Theodore Ts'o

fscrypt: drop inode argument from fscrypt_get_ctx()

The only reason the inode is being passed to fscrypt_get_ctx() is to
verify that the encryption key is available.  However, all callers
already ensure this because if we get as far as trying to do I/O to an
encrypted file without the key, there's already a bug.

Therefore, remove this unnecessary argument.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent dc4060a5
...@@ -104,7 +104,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, ...@@ -104,7 +104,7 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE); BUG_ON(inode->i_sb->s_blocksize != PAGE_SIZE);
ctx = fscrypt_get_ctx(inode, GFP_NOFS); ctx = fscrypt_get_ctx(GFP_NOFS);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return PTR_ERR(ctx); return PTR_ERR(ctx);
......
...@@ -87,23 +87,17 @@ EXPORT_SYMBOL(fscrypt_release_ctx); ...@@ -87,23 +87,17 @@ EXPORT_SYMBOL(fscrypt_release_ctx);
/** /**
* fscrypt_get_ctx() - Gets an encryption context * fscrypt_get_ctx() - Gets an encryption context
* @inode: The inode for which we are doing the crypto
* @gfp_flags: The gfp flag for memory allocation * @gfp_flags: The gfp flag for memory allocation
* *
* Allocates and initializes an encryption context. * Allocates and initializes an encryption context.
* *
* Return: An allocated and initialized encryption context on success; error * Return: A new encryption context on success; an ERR_PTR() otherwise.
* value or NULL otherwise.
*/ */
struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, gfp_t gfp_flags) struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
{ {
struct fscrypt_ctx *ctx = NULL; struct fscrypt_ctx *ctx;
struct fscrypt_info *ci = inode->i_crypt_info;
unsigned long flags; unsigned long flags;
if (ci == NULL)
return ERR_PTR(-ENOKEY);
/* /*
* We first try getting the ctx from a free list because in * We first try getting the ctx from a free list because in
* the common case the ctx will have an allocated and * the common case the ctx will have an allocated and
...@@ -258,9 +252,9 @@ struct page *fscrypt_encrypt_page(const struct inode *inode, ...@@ -258,9 +252,9 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
BUG_ON(!PageLocked(page)); BUG_ON(!PageLocked(page));
ctx = fscrypt_get_ctx(inode, gfp_flags); ctx = fscrypt_get_ctx(gfp_flags);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return (struct page *)ctx; return ERR_CAST(ctx);
/* The encryption operation will require a bounce page. */ /* The encryption operation will require a bounce page. */
ciphertext_page = fscrypt_alloc_bounce_page(ctx, gfp_flags); ciphertext_page = fscrypt_alloc_bounce_page(ctx, gfp_flags);
......
...@@ -244,7 +244,7 @@ int ext4_mpage_readpages(struct address_space *mapping, ...@@ -244,7 +244,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
struct fscrypt_ctx *ctx = NULL; struct fscrypt_ctx *ctx = NULL;
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) { if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) {
ctx = fscrypt_get_ctx(inode, GFP_NOFS); ctx = fscrypt_get_ctx(GFP_NOFS);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
goto set_error_page; goto set_error_page;
} }
......
...@@ -90,7 +90,7 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode) ...@@ -90,7 +90,7 @@ static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
/* crypto.c */ /* crypto.c */
extern void fscrypt_enqueue_decrypt_work(struct work_struct *); extern void fscrypt_enqueue_decrypt_work(struct work_struct *);
extern struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *, gfp_t); extern struct fscrypt_ctx *fscrypt_get_ctx(gfp_t);
extern void fscrypt_release_ctx(struct fscrypt_ctx *); extern void fscrypt_release_ctx(struct fscrypt_ctx *);
extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *, extern struct page *fscrypt_encrypt_page(const struct inode *, struct page *,
unsigned int, unsigned int, unsigned int, unsigned int,
...@@ -247,8 +247,7 @@ static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work) ...@@ -247,8 +247,7 @@ static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
{ {
} }
static inline struct fscrypt_ctx *fscrypt_get_ctx(const struct inode *inode, static inline struct fscrypt_ctx *fscrypt_get_ctx(gfp_t gfp_flags)
gfp_t gfp_flags)
{ {
return ERR_PTR(-EOPNOTSUPP); return ERR_PTR(-EOPNOTSUPP);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment