@@ -4916,6 +4916,7 @@ static int io_connect(struct io_kiocb *req, bool force_nonblock,
49164916struct io_poll_table {
49174917 struct poll_table_struct pt ;
49184918 struct io_kiocb * req ;
4919+ int nr_entries ;
49194920 int error ;
49204921};
49214922
@@ -5098,11 +5099,11 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
50985099 struct io_kiocb * req = pt -> req ;
50995100
51005101 /*
5101- * If poll->head is already set, it's because the file being polled
5102- * uses multiple waitqueues for poll handling (eg one for read, one
5103- * for write). Setup a separate io_poll_iocb if this happens.
5102+ * The file being polled uses multiple waitqueues for poll handling
5103+ * (e.g. one for read, one for write). Setup a separate io_poll_iocb
5104+ * if this happens.
51045105 */
5105- if (unlikely (poll -> head )) {
5106+ if (unlikely (pt -> nr_entries )) {
51065107 struct io_poll_iocb * poll_one = poll ;
51075108
51085109 /* already have a 2nd entry, fail a third attempt */
@@ -5124,7 +5125,7 @@ static void __io_queue_proc(struct io_poll_iocb *poll, struct io_poll_table *pt,
51245125 * poll_ptr = poll ;
51255126 }
51265127
5127- pt -> error = 0 ;
5128+ pt -> nr_entries ++ ;
51285129 poll -> head = head ;
51295130
51305131 if (poll -> events & EPOLLEXCLUSIVE )
@@ -5210,9 +5211,12 @@ static __poll_t __io_arm_poll_handler(struct io_kiocb *req,
52105211
52115212 ipt -> pt ._key = mask ;
52125213 ipt -> req = req ;
5213- ipt -> error = - EINVAL ;
5214+ ipt -> error = 0 ;
5215+ ipt -> nr_entries = 0 ;
52145216
52155217 mask = vfs_poll (req -> file , & ipt -> pt ) & poll -> events ;
5218+ if (unlikely (!ipt -> nr_entries ) && !ipt -> error )
5219+ ipt -> error = - EINVAL ;
52165220
52175221 spin_lock_irq (& ctx -> completion_lock );
52185222 if (likely (poll -> head )) {
0 commit comments