Unverified Commit e9d50b78 authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge patch series "fs: add iput_not_last()"

Add iput_not_last() and switch landlock over to it to remove
false-positives from might_sleep() annotations in iput().

Link: https://patch.msgid.link/20251105212025.807549-1-mjguzik@gmail.com

* patches from https://patch.msgid.link/20251105212025.807549-1-mjguzik@gmail.com

:
  landlock: fix splats from iput() after it started calling might_sleep()
  fs: add iput_not_last()

Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents 3cd1548a 56325e8c
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -1967,6 +1967,18 @@ void iput(struct inode *inode)
}
EXPORT_SYMBOL(iput);

/**
 *	iput_not_last	- put an inode assuming this is not the last reference
 *	@inode: inode to put
 */
void iput_not_last(struct inode *inode)
{
	VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 2, inode);

	WARN_ON(atomic_sub_return(1, &inode->i_count) == 0);
}
EXPORT_SYMBOL(iput_not_last);

#ifdef CONFIG_BLOCK
/**
 *	bmap	- find a block number in a file
+1 −0
Original line number Diff line number Diff line
@@ -2824,6 +2824,7 @@ extern int current_umask(void);

extern void ihold(struct inode * inode);
extern void iput(struct inode *);
void iput_not_last(struct inode *);
int inode_update_timestamps(struct inode *inode, int flags);
int generic_update_time(struct inode *, int);

+3 −4
Original line number Diff line number Diff line
@@ -1335,11 +1335,10 @@ static void hook_sb_delete(struct super_block *const sb)
			 * At this point, we own the ihold() reference that was
			 * originally set up by get_inode_object() and the
			 * __iget() reference that we just set in this loop
			 * walk.  Therefore the following call to iput() will
			 * not sleep nor drop the inode because there is now at
			 * least two references to it.
			 * walk.  Therefore there are at least two references
			 * on the inode.
			 */
			iput(inode);
			iput_not_last(inode);
		} else {
			spin_unlock(&object->lock);
			rcu_read_unlock();