Skip to content

Commit 257b1c2

Browse files
committed
file: add fput() cleanup helper
Add a simple helper to put a file reference. Link: https://lore.kernel.org/r/20240719-work-mount-namespace-v1-4-834113cab0d2@kernel.org Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5fcf329 commit 257b1c2

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

include/linux/file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/posix_types.h>
1212
#include <linux/errno.h>
1313
#include <linux/cleanup.h>
14+
#include <linux/err.h>
1415

1516
struct file;
1617

@@ -96,6 +97,7 @@ extern void put_unused_fd(unsigned int fd);
9697

9798
DEFINE_CLASS(get_unused_fd, int, if (_T >= 0) put_unused_fd(_T),
9899
get_unused_fd_flags(flags), unsigned flags)
100+
DEFINE_FREE(fput, struct file *, if (!IS_ERR_OR_NULL(_T)) fput(_T))
99101

100102
/*
101103
* take_fd() will take care to set @fd to -EBADF ensuring that

0 commit comments

Comments
 (0)