diff mbox series

[09/13] mm: move putting the page on error out of filemap_make_page_uptodate

Message ID 20201031090004.452516-10-hch@lst.de (mailing list archive)
State New
Headers show
Series [01/13] mm: simplify generic_file_buffered_read_readpage | expand

Commit Message

Christoph Hellwig Oct. 31, 2020, 9 a.m. UTC
Move the put_page on error from filemap_make_page_uptodate into the
callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 mm/filemap.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 6089f1d9dd429f..5f4937715689e7 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2219,11 +2219,11 @@  static int filemap_make_page_uptodate(struct kiocb *iocb, struct iov_iter *iter,
 	loff_t last = iocb->ki_pos + iter->count;
 	pgoff_t last_index = (last + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	loff_t pos = max(iocb->ki_pos, (loff_t)pg_index << PAGE_SHIFT);
-	int error = -EAGAIN;
+	int error;
 
 	if (PageReadahead(page)) {
 		if (iocb->ki_flags & IOCB_NOIO)
-			goto put_page;
+			return -EAGAIN;
 		page_cache_async_readahead(mapping, &file->f_ra, file, page,
 					   pg_index, last_index - pg_index);
 	}
@@ -2232,7 +2232,7 @@  static int filemap_make_page_uptodate(struct kiocb *iocb, struct iov_iter *iter,
 		return 0;
 
 	if (iocb->ki_flags & IOCB_NOWAIT)
-		goto put_page;
+		return -EAGAIN;
 
 	/*
 	 * See comment in do_read_cache_page on why wait_on_page_locked is used
@@ -2240,13 +2240,13 @@  static int filemap_make_page_uptodate(struct kiocb *iocb, struct iov_iter *iter,
 	 */
 	if (iocb->ki_flags & IOCB_WAITQ) {
 		if (!first)
-			goto put_page;
+			return -EAGAIN;
 		error = wait_on_page_locked_async(page, iocb->ki_waitq);
 	} else {
 		error = wait_on_page_locked_killable(page);
 	}
 	if (unlikely(error))
-		goto put_page;
+		return error;
 
 	if (PageUptodate(page))
 		return 0;
@@ -2274,27 +2274,19 @@  static int filemap_make_page_uptodate(struct kiocb *iocb, struct iov_iter *iter,
 	/* Get exclusive access to the page ... */
 	error = lock_page_for_iocb(iocb, page);
 	if (unlikely(error))
-		goto put_page;
+		return error;
 
 page_not_up_to_date_locked:
 	/* Did it get truncated before we got the lock? */
 	if (!page->mapping) {
 		unlock_page(page);
-		error = AOP_TRUNCATED_PAGE;
-		goto put_page;
+		return AOP_TRUNCATED_PAGE;
 	}
 
 	/* Did somebody else fill it already? */
 	if (PageUptodate(page))
 		goto unlock_page;
-	error = filemap_readpage(iocb, page);
-	if (error)
-		goto put_page;
-	return 0;
-
-put_page:
-	put_page(page);
-	return error;
+	return filemap_readpage(iocb, page);
 }
 
 static int filemap_new_page(struct kiocb *iocb, struct iov_iter *iter,
@@ -2317,7 +2309,10 @@  static int filemap_new_page(struct kiocb *iocb, struct iov_iter *iter,
 	error = filemap_readpage(iocb, *page);
 	if (error)
 		goto put_page;
-	return filemap_make_page_uptodate(iocb, iter, *page, index, true);
+	error = filemap_make_page_uptodate(iocb, iter, *page, index, true);
+	if (error)
+		goto put_page;
+	return 0;
 put_page:
 	put_page(*page);
 	return error;
@@ -2360,7 +2355,7 @@  static int filemap_read_pages(struct kiocb *iocb, struct iov_iter *iter,
 			err = filemap_make_page_uptodate(iocb, iter, pages[i],
 					index + i, i == 0);
 			if (err) {
-				for (j = i + 1; j < nr_pages; j++)
+				for (j = i; j < nr_pages; j++)
 					put_page(pages[j]);
 				nr_pages = i;
 				break;