aio_read_events_ring(): make a bit more readable
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 26 May 2018 23:13:10 +0000 (19:13 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 30 May 2018 03:18:17 +0000 (23:18 -0400)
The logics for 'avail' is
* not past the tail of cyclic buffer
* no more than asked
* not past the end of buffer
* not past the end of a page

Unobfuscate the last part.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/aio.c

index 6098b6ba86713614191bffa40fcc456f225f62b7..06761d5aac1e245f1d2ae845b362cdff43b867c2 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1197,14 +1197,13 @@ static long aio_read_events_ring(struct kioctx *ctx,
                if (head == tail)
                        break;
 
-               avail = min(avail, nr - ret);
-               avail = min_t(long, avail, AIO_EVENTS_PER_PAGE -
-                           ((head + AIO_EVENTS_OFFSET) % AIO_EVENTS_PER_PAGE));
-
                pos = head + AIO_EVENTS_OFFSET;
                page = ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE];
                pos %= AIO_EVENTS_PER_PAGE;
 
+               avail = min(avail, nr - ret);
+               avail = min_t(long, avail, AIO_EVENTS_PER_PAGE - pos);
+
                ev = kmap(page);
                copy_ret = copy_to_user(event + ret, ev + pos,
                                        sizeof(*ev) * avail);