]> www.infradead.org Git - users/hch/block.git/commitdiff
mm: simplify generic_file_buffered_read_pagenotuptodate
authorChristoph Hellwig <hch@lst.de>
Fri, 30 Oct 2020 09:07:53 +0000 (10:07 +0100)
committerChristoph Hellwig <hch@lst.de>
Fri, 30 Oct 2020 15:38:11 +0000 (16:38 +0100)
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

index 2e997890cc81c2865dc713b5299fcdf2077aa275..332f3a6781addcfbc98bebb01ad32ab67984f5eb 100644 (file)
@@ -2217,15 +2217,11 @@ out_put_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 @@ got_pages:
                                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;
                        }
                }