file: add fd_except cleanup class
Quoted 50 lines · Andreas Gruenbacher
CLASS(fd_except, f)(fd, mask) allows to specify whether to accept or rejectO_PATHfile descriptors by passing a mode value of 0 orFMODE_PATHrather than using a specific cleanup class for each case (CLASS(fd, f)(fd) orCLASS(fd_raw, f)(fd)).Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/file.c | 5 +++++ include/linux/file.h | 2 ++ 2 files changed, 7 insertions(+)fs/file.c +5
-0@@ -1211,6 +1211,11 @@ struct fd fdget(unsigned int fd) }EXPORT_SYMBOL (fdget); +struct fd fdget_except (unsigned int fd,fmode_t mask) +{ +return __fget_light (fd, mask); +} +struct fd fdget_raw (unsigned int fd) {return __fget_light (fd,0 );include/linux/file.h +2
-0@@ -70,6 +70,7 @@ extern struct file *fget_task_next(struct task_struct *task, unsigned int *fd);extern void __f_unlock_pos (struct file *);struct fd fdget (unsigned int fd); +struct fd fdget_except (unsigned int fd,fmode_t mask);struct fd fdget_raw (unsigned int fd);struct fd fdget_pos (unsigned int fd);@@ -81,6 +82,7 @@ static inline void fdput_pos(struct fd f) } DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd) +DEFINE_CLASS(fd_except, struct fd, fdput(_T), fdget_except(fd, mask), int fd, fmode_t mask) DEFINE_CLASS(fd_raw, struct fd, fdput(_T), fdget_raw(fd), int fd) DEFINE_CLASS(fd_pos, struct fd, fdput_pos(_T), fdget_pos(fd), int fd)Signature · 1 line
2.54.0
Looks fine to me, but I do dislike the fdget_except() name. Maybe if fd_raw() is only used for DEFINE_CLASS(fd_raw) anyway, we can just reuse it.