From patchwork Tue Apr 4 21:39:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9662603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56FD8602B9 for ; Tue, 4 Apr 2017 21:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48E292856D for ; Tue, 4 Apr 2017 21:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D7F028583; Tue, 4 Apr 2017 21:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E01428581 for ; Tue, 4 Apr 2017 21:40:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754546AbdDDVke (ORCPT ); Tue, 4 Apr 2017 17:40:34 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35604 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754494AbdDDVkd (ORCPT ); Tue, 4 Apr 2017 17:40:33 -0400 Received: by mail-pf0-f193.google.com with SMTP id n11so6504091pfg.2; Tue, 04 Apr 2017 14:40:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5tQBMae0zMFYFvoV3EGZdDhaG93nwGaivqZAa5eyEgg=; b=lmlwHWbNSsz3qrbnEAuipY29FWId7XnWhdWcYin0hWw9gvVKecnxQ0hidfmyJ0c3r6 HykgJapdYbw5XrRPxWRJMbng+AjiuYD5Ph1KWHeRS9YqdBYxy6zWbm2YsaFYgxy6In9j pQHQPXJP468MCjppUvu54lGDEi4cHuL9T0mViB/HiMRM54nEASlW3zcnrYx4Z6gEp/Ce LZpgLLB8tWOs4CN0niR+dlFxVJsVGHPQgliNXNREax4YstFZcWqqON5U/QjdBrwNEkK5 EKjOC4sU403eS6u8wN66ugTZyBPjmZj7H0KI2dlllrDVR+Bap+EVtkKYdhVkO6qEa7d3 9+LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5tQBMae0zMFYFvoV3EGZdDhaG93nwGaivqZAa5eyEgg=; b=qxOeBtKAMaXpiZfytnWFW99wbvZiqd83agbRMvTQ3H5KkxJB+Ag86+hk+shof9m8dx 9YN0m57o3iBSjfxCbfN77Cs4tamsJL7FMZHh36c+TlzCbiyQuHYzuWI2bcQZhQlmVfHn exQJcLp8ZWnqJszmfDTlxE/muPmdYfY8A899ZuLm7/cDH/DK/8gpQZYGCEQc00SKnXmM JYeF8tgjiybkcw+NCwNhs8tJHR4JZDILTUICmzqNvdegzdARypryjnoJaZyfEJexjelz wV+s1bEw+vVWjDZEe7vo6AdoX4oBT88ObBpp0RxZVpXlJrwwIP23dty3xpVYBr/+3QNz CaKQ== X-Gm-Message-State: AFeK/H2BqeUZZfLrMV4Ej6I5SpbLqMdqy0eDQfMkQW/8/fIqHJyRFjfBZJ7MhRGrtZg0Aw== X-Received: by 10.98.201.77 with SMTP id k74mr24958889pfg.74.1491342032196; Tue, 04 Apr 2017 14:40:32 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id t187sm33404112pfb.116.2017.04.04.14.40.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 04 Apr 2017 14:40:31 -0700 (PDT) From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, "Theodore Y . Ts'o" , Jaegeuk Kim , Eric Biggers Subject: [PATCH] fscrypt: remove unnecessary checks for NULL operations Date: Tue, 4 Apr 2017 14:39:41 -0700 Message-Id: <20170404213941.113427-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.2.715.g7642488e1d-goog Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers 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. Signed-off-by: Eric Biggers Reviewed-by: Richard Weinberger --- fs/crypto/keyinfo.c | 3 --- fs/crypto/policy.c | 11 +---------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/fs/crypto/keyinfo.c b/fs/crypto/keyinfo.c index 8cdfddce2b34..179e578b875b 100644 --- a/fs/crypto/keyinfo.c +++ b/fs/crypto/keyinfo.c @@ -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) || diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index 4908906d54d5..d71ec3780d0c 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c @@ -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;