From 7a163b2195cda0cddf47b5caf14a7229d4e2bea3 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 1 Feb 2018 15:13:18 -0500 Subject: unify {de,}mangle_poll(), get rid of kernel-side POLL... except, again, POLLFREE and POLL_BUSY_LOOP. With this, we finally get to the promised end result: - POLL{IN,OUT,...} are plain integers and *not* in __poll_t, so any stray instances of ->poll() still using those will be caught by sparse. - eventpoll.c and select.c warning-free wrt __poll_t - no more kernel-side definitions of POLL... - userland ones are visible through the entire kernel (and used pretty much only for mangle/demangle) - same behavior as after the first series (i.e. sparc et.al. epoll(2) working correctly). Signed-off-by: Al Viro Signed-off-by: Linus Torvalds --- include/linux/poll.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include/linux') diff --git a/include/linux/poll.h b/include/linux/poll.h index d23104b32931..f45ebd017eaa 100644 --- a/include/linux/poll.h +++ b/include/linux/poll.h @@ -108,4 +108,28 @@ extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp, extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec, long nsec); +#define __MAP(v, from, to) \ + (from < to ? (v & from) * (to/from) : (v & from) / (from/to)) + +static inline __u16 mangle_poll(__poll_t val) +{ + __u16 v = (__force __u16)val; +#define M(X) __MAP(v, (__force __u16)EPOLL##X, POLL##X) + return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) | + M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) | + M(HUP) | M(RDHUP) | M(MSG); +#undef M +} + +static inline __poll_t demangle_poll(u16 val) +{ +#define M(X) (__force __poll_t)__MAP(val, POLL##X, (__force __u16)EPOLL##X) + return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) | + M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) | + M(HUP) | M(RDHUP) | M(MSG); +#undef M +} +#undef __MAP + + #endif /* _LINUX_POLL_H */ -- cgit v1.2.3-59-g8ed1b