From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zeniv.linux.org.uk ([195.92.253.2]:58718 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754751AbeE1R5I (ORCPT ); Mon, 28 May 2018 13:57:08 -0400 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH v2 3/6] aio_read_events_ring(): make a bit more readable Date: Mon, 28 May 2018 18:57:04 +0100 Message-Id: <20180528175707.10926-3-viro@ZenIV.linux.org.uk> In-Reply-To: <20180528175707.10926-1-viro@ZenIV.linux.org.uk> References: <20180528175430.GC30522@ZenIV.linux.org.uk> <20180528175707.10926-1-viro@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: From: Al Viro 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 --- fs/aio.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index a8e4353ded2f..51843b057841 100644 --- 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); -- 2.11.0