Skip to content

Commit 113348a

Browse files
tasksetbrauner
authored andcommitted
eventfd: use wait_event_interruptible_locked_irq() helper
wait_event_interruptible_locked_irq was introduced by commit 22c43c8 ("wait_event_interruptible_locked() interface"), but older code such as eventfd_{write,read} still uses the open code implementation. Inspired by commit 8120a8a ("fs/timerfd.c: make use of wait_event_interruptible_locked_irq()"), this patch replaces the open code implementation with a single macro call. No functional change intended. Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Jens Axboe <axboe@kernel.dk> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@lst.de> Cc: Dylan Yudaken <dylany@fb.com> Cc: Jens Axboe <axboe@kernel.dk> Cc: David Woodhouse <dwmw@amazon.co.uk> Cc: Fu Wei <wefu@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Michal Nazarewicz <m.nazarewicz@samsung.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Message-Id: <tencent_16F9553E8354D950D704214D6EA407315F0A@qq.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 983652c commit 113348a

1 file changed

Lines changed: 7 additions & 34 deletions

File tree

fs/eventfd.c

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
228228
struct file *file = iocb->ki_filp;
229229
struct eventfd_ctx *ctx = file->private_data;
230230
__u64 ucnt = 0;
231-
DECLARE_WAITQUEUE(wait, current);
232231

233232
if (iov_iter_count(to) < sizeof(ucnt))
234233
return -EINVAL;
@@ -239,23 +238,11 @@ static ssize_t eventfd_read(struct kiocb *iocb, struct iov_iter *to)
239238
spin_unlock_irq(&ctx->wqh.lock);
240239
return -EAGAIN;
241240
}
242-
__add_wait_queue(&ctx->wqh, &wait);
243-
for (;;) {
244-
set_current_state(TASK_INTERRUPTIBLE);
245-
if (ctx->count)
246-
break;
247-
if (signal_pending(current)) {
248-
__remove_wait_queue(&ctx->wqh, &wait);
249-
__set_current_state(TASK_RUNNING);
250-
spin_unlock_irq(&ctx->wqh.lock);
251-
return -ERESTARTSYS;
252-
}
241+
242+
if (wait_event_interruptible_locked_irq(ctx->wqh, ctx->count)) {
253243
spin_unlock_irq(&ctx->wqh.lock);
254-
schedule();
255-
spin_lock_irq(&ctx->wqh.lock);
244+
return -ERESTARTSYS;
256245
}
257-
__remove_wait_queue(&ctx->wqh, &wait);
258-
__set_current_state(TASK_RUNNING);
259246
}
260247
eventfd_ctx_do_read(ctx, &ucnt);
261248
current->in_eventfd = 1;
@@ -275,7 +262,6 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
275262
struct eventfd_ctx *ctx = file->private_data;
276263
ssize_t res;
277264
__u64 ucnt;
278-
DECLARE_WAITQUEUE(wait, current);
279265

280266
if (count < sizeof(ucnt))
281267
return -EINVAL;
@@ -288,23 +274,10 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
288274
if (ULLONG_MAX - ctx->count > ucnt)
289275
res = sizeof(ucnt);
290276
else if (!(file->f_flags & O_NONBLOCK)) {
291-
__add_wait_queue(&ctx->wqh, &wait);
292-
for (res = 0;;) {
293-
set_current_state(TASK_INTERRUPTIBLE);
294-
if (ULLONG_MAX - ctx->count > ucnt) {
295-
res = sizeof(ucnt);
296-
break;
297-
}
298-
if (signal_pending(current)) {
299-
res = -ERESTARTSYS;
300-
break;
301-
}
302-
spin_unlock_irq(&ctx->wqh.lock);
303-
schedule();
304-
spin_lock_irq(&ctx->wqh.lock);
305-
}
306-
__remove_wait_queue(&ctx->wqh, &wait);
307-
__set_current_state(TASK_RUNNING);
277+
res = wait_event_interruptible_locked_irq(ctx->wqh,
278+
ULLONG_MAX - ctx->count > ucnt);
279+
if (!res)
280+
res = sizeof(ucnt);
308281
}
309282
if (likely(res > 0)) {
310283
ctx->count += ucnt;

0 commit comments

Comments
 (0)