]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs,fsverity: clear out fsverity_info from common code
authorChristoph Hellwig <hch@lst.de>
Wed, 28 Jan 2026 15:26:14 +0000 (16:26 +0100)
committerEric Biggers <ebiggers@kernel.org>
Thu, 29 Jan 2026 17:39:41 +0000 (09:39 -0800)
Free the fsverity_info directly in clear_inode instead of requiring file
systems to handle it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Acked-by: David Sterba <dsterba@suse.com> # btrfs
Link: https://lore.kernel.org/r/20260128152630.627409-3-hch@lst.de
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
fs/btrfs/inode.c
fs/ext4/super.c
fs/f2fs/inode.c
fs/inode.c
fs/verity/open.c
include/linux/fsverity.h

index a2b5b440637e67ae6762ddc9a6f883ab06e3ab71..67c64efc5099f7f284d6000e938ae1dbd3e56527 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/sched/mm.h>
 #include <linux/iomap.h>
 #include <linux/unaligned.h>
-#include <linux/fsverity.h>
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -5571,11 +5570,8 @@ void btrfs_evict_inode(struct inode *inode)
 
        trace_btrfs_inode_evict(inode);
 
-       if (!root) {
-               fsverity_cleanup_inode(inode);
-               clear_inode(inode);
-               return;
-       }
+       if (!root)
+               goto clear_inode;
 
        fs_info = inode_to_fs_info(inode);
        evict_inode_truncate_pages(inode);
@@ -5675,7 +5671,7 @@ out:
         * to retry these periodically in the future.
         */
        btrfs_remove_delayed_node(BTRFS_I(inode));
-       fsverity_cleanup_inode(inode);
+clear_inode:
        clear_inode(inode);
 }
 
index 87205660c5d026c3a73a64788757c288a03eaa5f..86131f4d87181bc59f0a2fa7087bfbe67b3e71eb 100644 (file)
@@ -1527,7 +1527,6 @@ void ext4_clear_inode(struct inode *inode)
                EXT4_I(inode)->jinode = NULL;
        }
        fscrypt_put_encryption_info(inode);
-       fsverity_cleanup_inode(inode);
 }
 
 static struct inode *ext4_nfs_get_inode(struct super_block *sb,
index 38b8994bc1b2c6a9eed97ee21b8e38d457cf9944..ee332b99434874e7cdf4650d0666e0ab8e7c09f4 100644 (file)
@@ -1000,7 +1000,6 @@ no_delete:
        }
 out_clear:
        fscrypt_put_encryption_info(inode);
-       fsverity_cleanup_inode(inode);
        clear_inode(inode);
 }
 
index 379f4c19845c959e878ef174f6d3b1defa905cac..38dbdfbb09bac26320455041e034100e4850e92e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/cdev.h>
 #include <linux/memblock.h>
 #include <linux/fsnotify.h>
+#include <linux/fsverity.h>
 #include <linux/mount.h>
 #include <linux/posix_acl.h>
 #include <linux/buffer_head.h> /* for inode_has_buffers */
@@ -773,6 +774,14 @@ void dump_mapping(const struct address_space *mapping)
 
 void clear_inode(struct inode *inode)
 {
+       /*
+        * Only IS_VERITY() inodes can have verity info, so start by checking
+        * for IS_VERITY() (which is faster than retrieving the pointer to the
+        * verity info).  This minimizes overhead for non-verity inodes.
+        */
+       if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode))
+               fsverity_cleanup_inode(inode);
+
        /*
         * We have to cycle the i_pages lock here because reclaim can be in the
         * process of removing the last page (in __filemap_remove_folio())
index 2aa5eae5a54039e890cffd56c7615a60f702ba32..090cb77326eea2aa758e6051042bb947b735c530 100644 (file)
@@ -384,14 +384,13 @@ int __fsverity_file_open(struct inode *inode, struct file *filp)
 }
 EXPORT_SYMBOL_GPL(__fsverity_file_open);
 
-void __fsverity_cleanup_inode(struct inode *inode)
+void fsverity_cleanup_inode(struct inode *inode)
 {
        struct fsverity_info **vi_addr = fsverity_info_addr(inode);
 
        fsverity_free_info(*vi_addr);
        *vi_addr = NULL;
 }
-EXPORT_SYMBOL_GPL(__fsverity_cleanup_inode);
 
 void __init fsverity_init_info_cache(void)
 {
index 86fb1708676bac9482308ab6337ae05cc286dfad..ea1ed2e6c2f96985471df9732a163e7fddd101af 100644 (file)
@@ -179,26 +179,6 @@ int fsverity_get_digest(struct inode *inode,
 /* open.c */
 
 int __fsverity_file_open(struct inode *inode, struct file *filp);
-void __fsverity_cleanup_inode(struct inode *inode);
-
-/**
- * fsverity_cleanup_inode() - free the inode's verity info, if present
- * @inode: an inode being evicted
- *
- * Filesystems must call this on inode eviction to free the inode's verity info.
- */
-static inline void fsverity_cleanup_inode(struct inode *inode)
-{
-       /*
-        * Only IS_VERITY() inodes can have verity info, so start by checking
-        * for IS_VERITY() (which is faster than retrieving the pointer to the
-        * verity info).  This minimizes overhead for non-verity inodes.
-        */
-       if (IS_VERITY(inode))
-               __fsverity_cleanup_inode(inode);
-       else
-               VFS_WARN_ON_ONCE(*fsverity_info_addr(inode) != NULL);
-}
 
 /* read_metadata.c */
 
@@ -250,10 +230,6 @@ static inline int __fsverity_file_open(struct inode *inode, struct file *filp)
        return -EOPNOTSUPP;
 }
 
-static inline void fsverity_cleanup_inode(struct inode *inode)
-{
-}
-
 /* read_metadata.c */
 
 static inline int fsverity_ioctl_read_metadata(struct file *filp,
@@ -331,4 +307,6 @@ static inline int fsverity_file_open(struct inode *inode, struct file *filp)
        return 0;
 }
 
+void fsverity_cleanup_inode(struct inode *inode);
+
 #endif /* _LINUX_FSVERITY_H */