Skip to content

Commit 8a4ab0b

Browse files
committed
fscrypt: constify inode parameter to filename encryption functions
Constify the struct inode parameter to fscrypt_fname_disk_to_usr() and the other filename encryption functions so that users don't have to pass in a non-const inode when they are dealing with a const one, as in [1]. [1] https://lkml.kernel.org/linux-ext4/20191203051049.44573-6-drosen@google.com/ Cc: Daniel Rosenberg <drosen@google.com> Link: https://lore.kernel.org/r/20191215213947.9521-1-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 2a5831b commit 8a4ab0b

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎fs/crypto/fname.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ static inline bool fscrypt_is_dot_dotdot(const struct qstr *str)
3434
*
3535
* Return: 0 on success, -errno on failure
3636
*/
37-
int fname_encrypt(struct inode *inode, const struct qstr *iname,
37+
int fname_encrypt(const struct inode *inode, const struct qstr *iname,
3838
u8 *out, unsigned int olen)
3939
{
4040
struct skcipher_request *req = NULL;
4141
DECLARE_CRYPTO_WAIT(wait);
42-
struct fscrypt_info *ci = inode->i_crypt_info;
42+
const struct fscrypt_info *ci = inode->i_crypt_info;
4343
struct crypto_skcipher *tfm = ci->ci_ctfm;
4444
union fscrypt_iv iv;
4545
struct scatterlist sg;
@@ -85,14 +85,14 @@ int fname_encrypt(struct inode *inode, const struct qstr *iname,
8585
*
8686
* Return: 0 on success, -errno on failure
8787
*/
88-
static int fname_decrypt(struct inode *inode,
89-
const struct fscrypt_str *iname,
90-
struct fscrypt_str *oname)
88+
static int fname_decrypt(const struct inode *inode,
89+
const struct fscrypt_str *iname,
90+
struct fscrypt_str *oname)
9191
{
9292
struct skcipher_request *req = NULL;
9393
DECLARE_CRYPTO_WAIT(wait);
9494
struct scatterlist src_sg, dst_sg;
95-
struct fscrypt_info *ci = inode->i_crypt_info;
95+
const struct fscrypt_info *ci = inode->i_crypt_info;
9696
struct crypto_skcipher *tfm = ci->ci_ctfm;
9797
union fscrypt_iv iv;
9898
int res;
@@ -247,10 +247,10 @@ EXPORT_SYMBOL(fscrypt_fname_free_buffer);
247247
*
248248
* Return: 0 on success, -errno on failure
249249
*/
250-
int fscrypt_fname_disk_to_usr(struct inode *inode,
251-
u32 hash, u32 minor_hash,
252-
const struct fscrypt_str *iname,
253-
struct fscrypt_str *oname)
250+
int fscrypt_fname_disk_to_usr(const struct inode *inode,
251+
u32 hash, u32 minor_hash,
252+
const struct fscrypt_str *iname,
253+
struct fscrypt_str *oname)
254254
{
255255
const struct qstr qname = FSTR_TO_QSTR(iname);
256256
struct fscrypt_digested_name digested_name;

‎fs/crypto/fscrypt_private.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ void fscrypt_generate_iv(union fscrypt_iv *iv, u64 lblk_num,
260260
const struct fscrypt_info *ci);
261261

262262
/* fname.c */
263-
extern int fname_encrypt(struct inode *inode, const struct qstr *iname,
263+
extern int fname_encrypt(const struct inode *inode, const struct qstr *iname,
264264
u8 *out, unsigned int olen);
265265
extern bool fscrypt_fname_encrypted_size(const struct inode *inode,
266266
u32 orig_len, u32 max_len,

‎include/linux/fscrypt.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ static inline void fscrypt_free_filename(struct fscrypt_name *fname)
153153
extern int fscrypt_fname_alloc_buffer(const struct inode *, u32,
154154
struct fscrypt_str *);
155155
extern void fscrypt_fname_free_buffer(struct fscrypt_str *);
156-
extern int fscrypt_fname_disk_to_usr(struct inode *, u32, u32,
157-
const struct fscrypt_str *, struct fscrypt_str *);
156+
extern int fscrypt_fname_disk_to_usr(const struct inode *inode,
157+
u32 hash, u32 minor_hash,
158+
const struct fscrypt_str *iname,
159+
struct fscrypt_str *oname);
158160

159161
#define FSCRYPT_FNAME_MAX_UNDIGESTED_SIZE 32
160162

@@ -438,7 +440,7 @@ static inline void fscrypt_fname_free_buffer(struct fscrypt_str *crypto_str)
438440
return;
439441
}
440442

441-
static inline int fscrypt_fname_disk_to_usr(struct inode *inode,
443+
static inline int fscrypt_fname_disk_to_usr(const struct inode *inode,
442444
u32 hash, u32 minor_hash,
443445
const struct fscrypt_str *iname,
444446
struct fscrypt_str *oname)

0 commit comments

Comments
 (0)