diff mbox series

[02/13] mm: simplify generic_file_buffered_read_pagenotuptodate

Message ID 20201031090004.452516-3-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, 8:59 a.m. UTC
Stop passing pointless arguments, and return an int instead of a page
struct that contains either the passed in page, an ERR_PTR or NULL and
use goto labels to share common code.

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

Patch

diff --git a/mm/filemap.c b/mm/filemap.c
index 2e997890cc81c2..c717cfe35cc72a 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2217,15 +2217,11 @@  static int filemap_readpage(struct kiocb *iocb, struct page *page)
 	return error;
 }
 
-static struct page *
-generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
-					   struct file *filp,
-					   struct iov_iter *iter,
-					   struct page *page,
-					   loff_t pos, loff_t count)
+static int generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
+		struct iov_iter *iter, struct page *page, loff_t pos,
+		loff_t count)
 {
-	struct address_space *mapping = filp->f_mapping;
-	struct inode *inode = mapping->host;
+	struct address_space *mapping = iocb->ki_filp->f_mapping;
 	int error;
 
 	/*
@@ -2239,15 +2235,14 @@  generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
 	} else {
 		error = wait_on_page_locked_killable(page);
 	}
-	if (unlikely(error)) {
-		put_page(page);
-		return ERR_PTR(error);
-	}
+	if (unlikely(error))
+		goto put_page;
+
 	if (PageUptodate(page))
-		return page;
+		return 0;
 
-	if (inode->i_blkbits == PAGE_SHIFT ||
-			!mapping->a_ops->is_partially_uptodate)
+	if (mapping->host->i_blkbits == PAGE_SHIFT ||
+	    !mapping->a_ops->is_partially_uptodate)
 		goto page_not_up_to_date;
 	/* pipes can't handle partially uptodate pages */
 	if (unlikely(iov_iter_is_pipe(iter)))
@@ -2260,38 +2255,33 @@  generic_file_buffered_read_pagenotuptodate(struct kiocb *iocb,
 	if (!mapping->a_ops->is_partially_uptodate(page,
 				pos & ~PAGE_MASK, count))
 		goto page_not_up_to_date_locked;
+
+unlock_page:
 	unlock_page(page);
-	return page;
+	return 0;
 
 page_not_up_to_date:
 	/* Get exclusive access to the page ... */
 	error = lock_page_for_iocb(iocb, page);
-	if (unlikely(error)) {
-		put_page(page);
-		return ERR_PTR(error);
-	}
+	if (unlikely(error))
+		goto put_page;
 
 page_not_up_to_date_locked:
 	/* Did it get truncated before we got the lock? */
 	if (!page->mapping) {
 		unlock_page(page);
-		put_page(page);
-		return NULL;
+		error = AOP_TRUNCATED_PAGE;
+		goto put_page;
 	}
 
 	/* Did somebody else fill it already? */
-	if (PageUptodate(page)) {
-		unlock_page(page);
-		return page;
-	}
+	if (PageUptodate(page))
+		goto unlock_page;
+	return filemap_readpage(iocb, page);
 
-	error = filemap_readpage(iocb, page);
-	if (error) {
-		if (error == AOP_TRUNCATED_PAGE)
-			return NULL;
-		return ERR_PTR(error);
-	}
-	return page;
+put_page:
+	put_page(page);
+	return error;
 }
 
 static struct page *
@@ -2395,13 +2385,14 @@  static int generic_file_buffered_read_get_pages(struct kiocb *iocb,
 				break;
 			}
 
-			page = generic_file_buffered_read_pagenotuptodate(iocb,
-					filp, iter, page, pg_pos, pg_count);
-			if (IS_ERR_OR_NULL(page)) {
+			err = generic_file_buffered_read_pagenotuptodate(iocb,
+					iter, page, pg_pos, pg_count);
+			if (err) {
+				if (err == AOP_TRUNCATED_PAGE)
+					err = 0;
 				for (j = i + 1; j < nr_got; j++)
 					put_page(pages[j]);
 				nr_got = i;
-				err = PTR_ERR_OR_ZERO(page);
 				break;
 			}
 		}