Skip to contentSkip to conversation

fscrypt: remove unnecessary checks for NULL operations

PATCH Applied Eric Biggers 3 participants 3 messages Apr 4, 2017 – Apr 30, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fscrypt: remove unnecessary checks for NULL operations

From: Eric Biggers <[email protected]>

The functions in fs/crypto/*.c are only called by filesystems configured with encryption support. Since the ->get_context(), ->set_context(), and ->empty_dir() operations are always provided in that case (and must be, otherwise there would be no way to get/set encryption policies, or in the case of ->get_context() even access encrypted files at all), there is no need to check for these operations being NULL and we can remove these unneeded checks.

---
 fs/crypto/keyinfo.c |  3 ---
 fs/crypto/policy.c  | 11 +----------
 2 files changed, 1 insertion(+), 13 deletions(-)
fs/crypto/keyinfo.c +0 -3
index 8cdfddce2b34..179e578b875b 100644
@@ -183,9 +183,6 @@ int fscrypt_get_encryption_info(struct inode *inode)
 	if (res)
 		return res;
 
-	if (!inode->i_sb->s_cop->get_context)
-		return -EOPNOTSUPP;
-
 	res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
 	if (res < 0) {
 		if (!fscrypt_dummy_context_enabled(inode) ||
fs/crypto/policy.c +1 -10
index 4908906d54d5..d71ec3780d0c 100644
@@ -34,9 +34,6 @@ static int create_encryption_context_from_policy(struct inode *inode,
 {
 	struct fscrypt_context ctx;
 
-	if (!inode->i_sb->s_cop->set_context)
-		return -EOPNOTSUPP;
-
 	ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
 	memcpy(ctx.master_key_descriptor, policy->master_key_descriptor,
 					FS_KEY_DESCRIPTOR_SIZE);
@@ -87,8 +84,6 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
 	if (ret == -ENODATA) {
 		if (!S_ISDIR(inode->i_mode))
 			ret = -ENOTDIR;
-		else if (!inode->i_sb->s_cop->empty_dir)
-			ret = -EOPNOTSUPP;
 		else if (!inode->i_sb->s_cop->empty_dir(inode))
 			ret = -ENOTEMPTY;
 		else
@@ -118,8 +113,7 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
 	struct fscrypt_policy policy;
 	int res;
 
-	if (!inode->i_sb->s_cop->get_context ||
-			!inode->i_sb->s_cop->is_encrypted(inode))
+	if (!inode->i_sb->s_cop->is_encrypted(inode))
 		return -ENODATA;
 
 	res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
@@ -202,9 +196,6 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child,
 	struct fscrypt_info *ci;
 	int res;
 
-	if (!parent->i_sb->s_cop->set_context)
-		return -EOPNOTSUPP;
-
 	res = fscrypt_get_encryption_info(parent);
 	if (res < 0)
 		return res;
Signature · 1 line
2.12.2.715.g7642488e1d-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 64 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The functions in fs/crypto/*.c are only called by filesystems configured with encryption support. Since the ->get_context(), ->set_context(), and ->empty_dir() operations are always provided in that case (and must be, otherwise there would be no way to get/set encryption policies, or in the case of ->get_context() even access encrypted files at all), there is no need to check for these operations being NULL and we can remove these unneeded checks.

---
 fs/crypto/keyinfo.c |  3 ---
 fs/crypto/policy.c  | 11 +----------
 2 files changed, 1 insertion(+), 13 deletions(-)
fs/crypto/keyinfo.c +0 -3
index 8cdfddce2b34..179e578b875b 100644
@@ -183,9 +183,6 @@ int fscrypt_get_encryption_info(struct inode *inode)
        if (res)
                return res;
 
-       if (!inode->i_sb->s_cop->get_context)
-               return -EOPNOTSUPP;
-
        res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
        if (res < 0) {
                if (!fscrypt_dummy_context_enabled(inode) ||
fs/crypto/policy.c +1 -7
index 4908906d54d5..d71ec3780d0c 100644
@@ -34,9 +34,6 @@ static int create_encryption_context_from_policy(struct inode *inode,
 {
        struct fscrypt_context ctx;
 
-       if (!inode->i_sb->s_cop->set_context)
-               return -EOPNOTSUPP;
-
        ctx.format = FS_ENCRYPTION_CONTEXT_FORMAT_V1;
        memcpy(ctx.master_key_descriptor, policy->master_key_descriptor,
                                        FS_KEY_DESCRIPTOR_SIZE);
@@ -87,8 +84,6 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
        if (ret == -ENODATA) {
                if (!S_ISDIR(inode->i_mode))
                        ret = -ENOTDIR;
-               else if (!inode->i_sb->s_cop->empty_dir)
-                       ret = -EOPNOTSUPP;
                else if (!inode->i_sb->s_cop->empty_dir(inode))
                        ret = -ENOTEMPTY;
                else
@@ -118,8 +113,7 @@ int fscrypt_ioctl_get_policy(struct file *filp, void __user *arg)
        struct fscrypt_policy policy;
        int res;
 
-       if (!inode->i_sb->s_cop->get_context ||
-                       !inode->i_sb->s_cop->is_encrypted(inode))
+       if (!inode->i_sb->s_cop->is_encrypted(inode))
                return -ENODATA;
 
        res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));

fs/crypto/policy.c int fscrypt_inherit_context(struct inode *parent, struct inode *child, · line 201

Quoted 9 lines
fs/crypto/policy.c +0 -3
@@ -202,9 +196,6 @@ int fscrypt_inherit_context(struct inode *parent, struct inode *child,
        struct fscrypt_info *ci;
        int res;
 
-       if (!parent->i_sb->s_cop->set_context)
-               return -EOPNOTSUPP;
-
        res = fscrypt_get_encryption_info(parent);
        if (res < 0)
                return res;
Signature · 2 lines
Thanks,
//richard
maintainer Applied
#2 lore raw
In reply to Eric Biggers
Quoted 10 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The functions in fs/crypto/*.c are only called by filesystems configured with encryption support. Since the ->get_context(), ->set_context(), and ->empty_dir() operations are always provided in that case (and must be, otherwise there would be no way to get/set encryption policies, or in the case of ->get_context() even access encrypted files at all), there is no need to check for these operations being NULL and we can remove these unneeded checks.

Quoted 2 lines

Thanks, applied.

- Ted