From: Oleg Nesterov Date: Thu, 22 Apr 2021 06:43:06 +0000 (+1000) Subject: aio: simplify read_events() X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=261f475dd4ae3952cbce0e28c057ba861cad34d5;p=users%2Fjedix%2Flinux-maple.git aio: simplify read_events() Change wait_event_hrtimeout() to not call __wait_event_hrtimeout() if timeout == 0, this matches other _timeout() helpers in wait.h. This allows to simplify its only user, read_events(), it no longer needs to optimize the "until == 0" case by hand. Note: this patch doesn't use ___wait_cond_timeout because _hrtimeout() also differs in that it returns 0 if succeeds and -ETIME on timeout. Perhaps we should change this to make it fully compatible with other helpers. Link: http://lkml.kernel.org/r/20190607175413.GA29187@redhat.com Signed-off-by: Oleg Nesterov Reviewed-by: Andrew Morton Cc: Benjamin LaHaise Cc: Arnd Bergmann Cc: David Laight Cc: Deepa Dinamani Cc: "Eric W. Biederman" Cc: Eric Wong Cc: Peter Zijlstra Cc: Al Viro Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- diff --git a/fs/aio.c b/fs/aio.c index 76ce0cc3ee4e..e499cbcef117 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1286,12 +1286,9 @@ static long read_events(struct kioctx *ctx, long min_nr, long nr, * the ringbuffer empty. So in practice we should be ok, but it's * something to be aware of when touching this code. */ - if (until == 0) - aio_read_events(ctx, min_nr, nr, event, &ret); - else - wait_event_interruptible_hrtimeout(ctx->wait, - aio_read_events(ctx, min_nr, nr, event, &ret), - until); + wait_event_interruptible_hrtimeout(ctx->wait, + aio_read_events(ctx, min_nr, nr, event, &ret), + until); return ret; } diff --git a/include/linux/wait.h b/include/linux/wait.h index fe10e8570a52..cffb6f8d3b0b 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -555,7 +555,7 @@ do { \ ({ \ int __ret = 0; \ might_sleep(); \ - if (!(condition)) \ + if (!(condition) && (timeout)) \ __ret = __wait_event_hrtimeout(wq_head, condition, timeout, \ TASK_UNINTERRUPTIBLE); \ __ret; \ @@ -581,7 +581,7 @@ do { \ ({ \ long __ret = 0; \ might_sleep(); \ - if (!(condition)) \ + if (!(condition) && (timeout)) \ __ret = __wait_event_hrtimeout(wq, condition, timeout, \ TASK_INTERRUPTIBLE); \ __ret; \