diff options
author | Peter Zijlstra <peterz@infradead.org> | 2023-05-26 12:23:48 +0200 |
---|---|---|
committer | Peter Zijlstra <peterz@infradead.org> | 2023-06-26 11:14:18 +0200 |
commit | 54da6a0924311c7cf5015533991e44fb8eb12773 (patch) | |
tree | af497256995d40431b9c214e7faa45639bf3d991 /include/linux/file.h | |
parent | 9a1f37ebcfe061721564042254719dc8fd5c9fa0 (diff) | |
download | lwn-54da6a0924311c7cf5015533991e44fb8eb12773.tar.gz lwn-54da6a0924311c7cf5015533991e44fb8eb12773.zip |
locking: Introduce __cleanup() based infrastructure
Use __attribute__((__cleanup__(func))) to build:
- simple auto-release pointers using __free()
- 'classes' with constructor and destructor semantics for
scope-based resource management.
- lock guards based on the above classes.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230612093537.614161713%40infradead.org
Diffstat (limited to 'include/linux/file.h')
-rw-r--r-- | include/linux/file.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/include/linux/file.h b/include/linux/file.h index 39704eae83e2..6e9099d29343 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -10,6 +10,7 @@ #include <linux/types.h> #include <linux/posix_types.h> #include <linux/errno.h> +#include <linux/cleanup.h> struct file; @@ -80,6 +81,8 @@ static inline void fdput_pos(struct fd f) fdput(f); } +DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd) + extern int f_dupfd(unsigned int from, struct file *file, unsigned flags); extern int replace_fd(unsigned fd, struct file *file, unsigned flags); extern void set_close_on_exec(unsigned int fd, int flag); @@ -88,6 +91,9 @@ extern int __get_unused_fd_flags(unsigned flags, unsigned long nofile); extern int get_unused_fd_flags(unsigned flags); extern void put_unused_fd(unsigned int fd); +DEFINE_CLASS(get_unused_fd, int, if (_T >= 0) put_unused_fd(_T), + get_unused_fd_flags(flags), unsigned flags) + extern void fd_install(unsigned int fd, struct file *file); extern int __receive_fd(struct file *file, int __user *ufd, |