Skip to content

Commit

Permalink
ubifs: Remove #ifdef around CONFIG_FS_ENCRYPTION
Browse files Browse the repository at this point in the history
ifdefs reduce readablity and compile coverage. This removes the ifdefs
around CONFIG_FS_ENCRYPTION by using IS_ENABLED and relying on static
inline wrappers. A new static inline wrapper for setting sb->s_cop is
introduced to allow filesystems to unconditionally compile in their
s_cop operations.

Signed-off-by: Sascha Hauer <[email protected]>
Signed-off-by: Richard Weinberger <[email protected]>
  • Loading branch information
saschahauer authored and richardweinberger committed May 7, 2019
1 parent 9ca2d73 commit eea2c05
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
4 changes: 0 additions & 4 deletions fs/ubifs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,13 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return err;
}
case FS_IOC_SET_ENCRYPTION_POLICY: {
#ifdef CONFIG_FS_ENCRYPTION
struct ubifs_info *c = inode->i_sb->s_fs_info;

err = ubifs_enable_encryption(c);
if (err)
return err;

return fscrypt_ioctl_set_policy(file, (const void __user *)arg);
#else
return -EOPNOTSUPP;
#endif
}
case FS_IOC_GET_ENCRYPTION_POLICY:
return fscrypt_ioctl_get_policy(file, (void __user *)arg);
Expand Down
7 changes: 4 additions & 3 deletions fs/ubifs/sb.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,14 +748,12 @@ int ubifs_read_superblock(struct ubifs_info *c)
goto out;
}

#ifndef CONFIG_FS_ENCRYPTION
if (c->encrypted) {
if (!IS_ENABLED(CONFIG_UBIFS_FS_ENCRYPTION) && c->encrypted) {
ubifs_err(c, "file system contains encrypted files but UBIFS"
" was built without crypto support.");
err = -EINVAL;
goto out;
}
#endif

/* Automatically increase file system size to the maximum size */
c->old_leb_cnt = c->leb_cnt;
Expand Down Expand Up @@ -943,6 +941,9 @@ int ubifs_enable_encryption(struct ubifs_info *c)
int err;
struct ubifs_sb_node *sup = c->sup_node;

if (!IS_ENABLED(CONFIG_UBIFS_FS_ENCRYPTION))
return -EOPNOTSUPP;

if (c->encrypted)
return 0;

Expand Down
4 changes: 1 addition & 3 deletions fs/ubifs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -2146,9 +2146,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
#ifdef CONFIG_UBIFS_FS_XATTR
sb->s_xattr = ubifs_xattr_handlers;
#endif
#ifdef CONFIG_FS_ENCRYPTION
sb->s_cop = &ubifs_crypt_operations;
#endif
fscrypt_set_ops(sb, &ubifs_crypt_operations);

mutex_lock(&c->umount_mutex);
err = mount_ubifs(c);
Expand Down
11 changes: 11 additions & 0 deletions include/linux/fscrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
unsigned int max_size,
struct delayed_call *done);
static inline void fscrypt_set_ops(struct super_block *sb,
const struct fscrypt_operations *s_cop)
{
sb->s_cop = s_cop;
}
#else /* !CONFIG_FS_ENCRYPTION */

static inline bool fscrypt_has_encryption_key(const struct inode *inode)
Expand Down Expand Up @@ -446,6 +451,12 @@ static inline const char *fscrypt_get_symlink(struct inode *inode,
{
return ERR_PTR(-EOPNOTSUPP);
}

static inline void fscrypt_set_ops(struct super_block *sb,
const struct fscrypt_operations *s_cop)
{
}

#endif /* !CONFIG_FS_ENCRYPTION */

/**
Expand Down

0 comments on commit eea2c05

Please sign in to comment.