Skip to content

Commit eea2c05

Browse files
saschahauerrichardweinberger
authored andcommitted
ubifs: Remove #ifdef around CONFIG_FS_ENCRYPTION
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]>
1 parent 9ca2d73 commit eea2c05

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

fs/ubifs/ioctl.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,13 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
193193
return err;
194194
}
195195
case FS_IOC_SET_ENCRYPTION_POLICY: {
196-
#ifdef CONFIG_FS_ENCRYPTION
197196
struct ubifs_info *c = inode->i_sb->s_fs_info;
198197

199198
err = ubifs_enable_encryption(c);
200199
if (err)
201200
return err;
202201

203202
return fscrypt_ioctl_set_policy(file, (const void __user *)arg);
204-
#else
205-
return -EOPNOTSUPP;
206-
#endif
207203
}
208204
case FS_IOC_GET_ENCRYPTION_POLICY:
209205
return fscrypt_ioctl_get_policy(file, (void __user *)arg);

fs/ubifs/sb.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,14 +748,12 @@ int ubifs_read_superblock(struct ubifs_info *c)
748748
goto out;
749749
}
750750

751-
#ifndef CONFIG_FS_ENCRYPTION
752-
if (c->encrypted) {
751+
if (!IS_ENABLED(CONFIG_UBIFS_FS_ENCRYPTION) && c->encrypted) {
753752
ubifs_err(c, "file system contains encrypted files but UBIFS"
754753
" was built without crypto support.");
755754
err = -EINVAL;
756755
goto out;
757756
}
758-
#endif
759757

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

944+
if (!IS_ENABLED(CONFIG_UBIFS_FS_ENCRYPTION))
945+
return -EOPNOTSUPP;
946+
946947
if (c->encrypted)
947948
return 0;
948949

fs/ubifs/super.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,9 +2146,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
21462146
#ifdef CONFIG_UBIFS_FS_XATTR
21472147
sb->s_xattr = ubifs_xattr_handlers;
21482148
#endif
2149-
#ifdef CONFIG_FS_ENCRYPTION
2150-
sb->s_cop = &ubifs_crypt_operations;
2151-
#endif
2149+
fscrypt_set_ops(sb, &ubifs_crypt_operations);
21522150

21532151
mutex_lock(&c->umount_mutex);
21542152
err = mount_ubifs(c);

include/linux/fscrypt.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ extern int __fscrypt_encrypt_symlink(struct inode *inode, const char *target,
230230
extern const char *fscrypt_get_symlink(struct inode *inode, const void *caddr,
231231
unsigned int max_size,
232232
struct delayed_call *done);
233+
static inline void fscrypt_set_ops(struct super_block *sb,
234+
const struct fscrypt_operations *s_cop)
235+
{
236+
sb->s_cop = s_cop;
237+
}
233238
#else /* !CONFIG_FS_ENCRYPTION */
234239

235240
static inline bool fscrypt_has_encryption_key(const struct inode *inode)
@@ -446,6 +451,12 @@ static inline const char *fscrypt_get_symlink(struct inode *inode,
446451
{
447452
return ERR_PTR(-EOPNOTSUPP);
448453
}
454+
455+
static inline void fscrypt_set_ops(struct super_block *sb,
456+
const struct fscrypt_operations *s_cop)
457+
{
458+
}
459+
449460
#endif /* !CONFIG_FS_ENCRYPTION */
450461

451462
/**

0 commit comments

Comments
 (0)