Skip to content

Commit 7a163b2

Browse files
Al Virotorvalds
authored andcommitted
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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a9a0884 commit 7a163b2

File tree

8 files changed

+47
-142
lines changed

8 files changed

+47
-142
lines changed

arch/blackfin/include/uapi/asm/poll.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,8 @@
99
#ifndef _UAPI__BFIN_POLL_H
1010
#define _UAPI__BFIN_POLL_H
1111

12-
#ifndef __KERNEL__
1312
#define POLLWRNORM POLLOUT
14-
#define POLLWRBAND (__force __poll_t)256
15-
#else
16-
#define __ARCH_HAS_MANGLED_POLL
17-
static inline __u16 mangle_poll(__poll_t val)
18-
{
19-
__u16 v = (__force __u16)val;
20-
/* bit 9 -> bit 8, bit 8 -> bit 2 */
21-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6);
22-
}
23-
24-
static inline __poll_t demangle_poll(__u16 v)
25-
{
26-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
27-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
28-
((v & 4) << 6));
29-
}
30-
#endif
13+
#define POLLWRBAND 256
3114

3215
#include <asm-generic/poll.h>
3316

arch/frv/include/uapi/asm/poll.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,8 @@
22
#ifndef _ASM_POLL_H
33
#define _ASM_POLL_H
44

5-
#ifndef __KERNEL__
65
#define POLLWRNORM POLLOUT
7-
#define POLLWRBAND (__force __poll_t)256
8-
#else
9-
#define __ARCH_HAS_MANGLED_POLL
10-
static inline __u16 mangle_poll(__poll_t val)
11-
{
12-
__u16 v = (__force __u16)val;
13-
/* bit 9 -> bit 8, bit 8 -> bit 2 */
14-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6);
15-
}
16-
17-
static inline __poll_t demangle_poll(__u16 v)
18-
{
19-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
20-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
21-
((v & 4) << 6));
22-
}
23-
#endif
6+
#define POLLWRBAND 256
247

258
#include <asm-generic/poll.h>
269
#undef POLLREMOVE

arch/m68k/include/uapi/asm/poll.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,8 @@
22
#ifndef __m68k_POLL_H
33
#define __m68k_POLL_H
44

5-
#ifndef __KERNEL__
65
#define POLLWRNORM POLLOUT
7-
#define POLLWRBAND (__force __poll_t)256
8-
#else
9-
#define __ARCH_HAS_MANGLED_POLL
10-
static inline __u16 mangle_poll(__poll_t val)
11-
{
12-
__u16 v = (__force __u16)val;
13-
/* bit 9 -> bit 8, bit 8 -> bit 2 */
14-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6);
15-
}
16-
17-
static inline __poll_t demangle_poll(__u16 v)
18-
{
19-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
20-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
21-
((v & 4) << 6));
22-
}
23-
#endif
6+
#define POLLWRBAND 256
247

258
#include <asm-generic/poll.h>
269

arch/mips/include/uapi/asm/poll.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,8 @@
22
#ifndef __ASM_POLL_H
33
#define __ASM_POLL_H
44

5-
#ifndef __KERNEL__
65
#define POLLWRNORM POLLOUT
7-
#define POLLWRBAND (__force __poll_t)0x0100
8-
#else
9-
#define __ARCH_HAS_MANGLED_POLL
10-
static inline __u16 mangle_poll(__poll_t val)
11-
{
12-
__u16 v = (__force __u16)val;
13-
/* bit 9 -> bit 8, bit 8 -> bit 2 */
14-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6);
15-
}
16-
17-
static inline __poll_t demangle_poll(__u16 v)
18-
{
19-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
20-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
21-
((v & 4) << 6));
22-
}
23-
#endif
6+
#define POLLWRBAND 0x0100
247

258
#include <asm-generic/poll.h>
269

arch/sparc/include/uapi/asm/poll.h

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,11 @@
22
#ifndef __SPARC_POLL_H
33
#define __SPARC_POLL_H
44

5-
#ifndef __KERNEL__
65
#define POLLWRNORM POLLOUT
7-
#define POLLWRBAND (__force __poll_t)256
8-
#define POLLMSG (__force __poll_t)512
9-
#define POLLREMOVE (__force __poll_t)1024
10-
#define POLLRDHUP (__force __poll_t)2048
11-
#else
12-
#define __ARCH_HAS_MANGLED_POLL
13-
static inline __u16 mangle_poll(__poll_t val)
14-
{
15-
__u16 v = (__force __u16)val;
16-
/* bit 9 -> bit 8, bit 8 -> bit 2, bit 13 -> bit 11 */
17-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6) |
18-
((v & 0x2000) >> 2);
19-
20-
21-
}
22-
23-
static inline __poll_t demangle_poll(__u16 v)
24-
{
25-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
26-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
27-
((v & 4) << 6) | ((v & 0x800) << 2));
28-
}
29-
#endif
6+
#define POLLWRBAND 256
7+
#define POLLMSG 512
8+
#define POLLREMOVE 1024
9+
#define POLLRDHUP 2048
3010

3111
#include <asm-generic/poll.h>
3212

arch/xtensa/include/uapi/asm/poll.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,9 @@
1212
#ifndef _XTENSA_POLL_H
1313
#define _XTENSA_POLL_H
1414

15-
#ifndef __KERNEL__
1615
#define POLLWRNORM POLLOUT
17-
#define POLLWRBAND (__force __poll_t)0x0100
18-
#define POLLREMOVE (__force __poll_t)0x0800
19-
#else
20-
#define __ARCH_HAS_MANGLED_POLL
21-
static inline __u16 mangle_poll(__poll_t val)
22-
{
23-
__u16 v = (__force __u16)val;
24-
/* bit 9 -> bit 8, bit 8 -> bit 2 */
25-
return (v & ~0x300) | ((v & 0x200) >> 1) | ((v & 0x100) >> 6);
26-
}
27-
28-
static inline __poll_t demangle_poll(__u16 v)
29-
{
30-
/* bit 8 -> bit 9, bit 2 -> bits 2 and 8 */
31-
return (__force __poll_t)((v & ~0x100) | ((v & 0x100) << 1) |
32-
((v & 4) << 6));
33-
}
34-
#endif
16+
#define POLLWRBAND 0x0100
17+
#define POLLREMOVE 0x0800
3518

3619
#include <asm-generic/poll.h>
3720

include/linux/poll.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,28 @@ extern int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
108108
extern int poll_select_set_timeout(struct timespec64 *to, time64_t sec,
109109
long nsec);
110110

111+
#define __MAP(v, from, to) \
112+
(from < to ? (v & from) * (to/from) : (v & from) / (from/to))
113+
114+
static inline __u16 mangle_poll(__poll_t val)
115+
{
116+
__u16 v = (__force __u16)val;
117+
#define M(X) __MAP(v, (__force __u16)EPOLL##X, POLL##X)
118+
return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) |
119+
M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) |
120+
M(HUP) | M(RDHUP) | M(MSG);
121+
#undef M
122+
}
123+
124+
static inline __poll_t demangle_poll(u16 val)
125+
{
126+
#define M(X) (__force __poll_t)__MAP(val, POLL##X, (__force __u16)EPOLL##X)
127+
return M(IN) | M(OUT) | M(PRI) | M(ERR) | M(NVAL) |
128+
M(RDNORM) | M(RDBAND) | M(WRNORM) | M(WRBAND) |
129+
M(HUP) | M(RDHUP) | M(MSG);
130+
#undef M
131+
}
132+
#undef __MAP
133+
134+
111135
#endif /* _LINUX_POLL_H */

include/uapi/asm-generic/poll.h

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,36 @@
33
#define __ASM_GENERIC_POLL_H
44

55
/* These are specified by iBCS2 */
6-
#define POLLIN (__force __poll_t)0x0001
7-
#define POLLPRI (__force __poll_t)0x0002
8-
#define POLLOUT (__force __poll_t)0x0004
9-
#define POLLERR (__force __poll_t)0x0008
10-
#define POLLHUP (__force __poll_t)0x0010
11-
#define POLLNVAL (__force __poll_t)0x0020
6+
#define POLLIN 0x0001
7+
#define POLLPRI 0x0002
8+
#define POLLOUT 0x0004
9+
#define POLLERR 0x0008
10+
#define POLLHUP 0x0010
11+
#define POLLNVAL 0x0020
1212

1313
/* The rest seem to be more-or-less nonstandard. Check them! */
14-
#define POLLRDNORM (__force __poll_t)0x0040
15-
#define POLLRDBAND (__force __poll_t)0x0080
14+
#define POLLRDNORM 0x0040
15+
#define POLLRDBAND 0x0080
1616
#ifndef POLLWRNORM
17-
#define POLLWRNORM (__force __poll_t)0x0100
17+
#define POLLWRNORM 0x0100
1818
#endif
1919
#ifndef POLLWRBAND
20-
#define POLLWRBAND (__force __poll_t)0x0200
20+
#define POLLWRBAND 0x0200
2121
#endif
2222
#ifndef POLLMSG
23-
#define POLLMSG (__force __poll_t)0x0400
23+
#define POLLMSG 0x0400
2424
#endif
2525
#ifndef POLLREMOVE
26-
#define POLLREMOVE (__force __poll_t)0x1000
26+
#define POLLREMOVE 0x1000
2727
#endif
2828
#ifndef POLLRDHUP
29-
#define POLLRDHUP (__force __poll_t)0x2000
29+
#define POLLRDHUP 0x2000
3030
#endif
3131

3232
#define POLLFREE (__force __poll_t)0x4000 /* currently only for epoll */
3333

3434
#define POLL_BUSY_LOOP (__force __poll_t)0x8000
3535

36-
#ifdef __KERNEL__
37-
#ifndef __ARCH_HAS_MANGLED_POLL
38-
static inline __u16 mangle_poll(__poll_t val)
39-
{
40-
return (__force __u16)val;
41-
}
42-
43-
static inline __poll_t demangle_poll(__u16 v)
44-
{
45-
return (__force __poll_t)v;
46-
}
47-
#endif
48-
#endif
49-
5036
struct pollfd {
5137
int fd;
5238
short events;

0 commit comments

Comments
 (0)