From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5909C388F7 for ; Sat, 31 Oct 2020 09:06:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4E2A620756 for ; Sat, 31 Oct 2020 09:06:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="b5SHlqYU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4E2A620756 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BBEFB6B0036; Sat, 31 Oct 2020 05:06:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B70046B005C; Sat, 31 Oct 2020 05:06:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5F346B005D; Sat, 31 Oct 2020 05:06:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0038.hostedemail.com [216.40.44.38]) by kanga.kvack.org (Postfix) with ESMTP id 78AFD6B0036 for ; Sat, 31 Oct 2020 05:06:42 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 28E2433CD for ; Sat, 31 Oct 2020 09:06:42 +0000 (UTC) X-FDA: 77431640244.04.force25_2e04c162729d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 1149C8005050 for ; Sat, 31 Oct 2020 09:06:42 +0000 (UTC) X-HE-Tag: force25_2e04c162729d X-Filterd-Recvd-Size: 5377 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Sat, 31 Oct 2020 09:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UhjBocD9yV7vleGZemMhqxRkxBzWAvsA1Wt9SDILgQE=; b=b5SHlqYU5G3+SmN+u5SR0LlG8C BTFqhQLOoRnZHy3KYgfOy97MJKbm9ykalT3/zTPvErfjA1NrftfvBF6sFepKFVZiPDK4a1yol+S6I mlwhwKvwKQ47jL1yT2M85T6ulDw3WiQ+unelr+p3NUGNwcy080uMoNcJ0B/NjQ9QmRlkmMuIETcnz kPQ+rP+1tV+DzLWdWw3dzLU3rFYAfhzM0LbjeSPTkVXwGpgJAHA8QVqJ4EznWsKPzwKz1G6gKNqyi xDn0bf42iyU54YL+QsZccEpvmU3QoHSncLRgVeoe1uODpiwhVeMijaIaK2QB4YuZFvAfd2DpmibvZ /TntT/GA==; Received: from 089144193201.atnat0002.highway.a1.net ([89.144.193.201] helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYmqK-0007Fl-R6; Sat, 31 Oct 2020 09:06:37 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Kent Overstreet , Matthew Wilcox , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 02/13] mm: simplify generic_file_buffered_read_pagenotuptodate Date: Sat, 31 Oct 2020 09:59:53 +0100 Message-Id: <20201031090004.452516-3-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201031090004.452516-1-hch@lst.de> References: <20201031090004.452516-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- mm/filemap.c | 65 ++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 37 deletions(-) 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, s= truct page *page) return error; } =20 -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 =3D filp->f_mapping; - struct inode *inode =3D mapping->host; + struct address_space *mapping =3D iocb->ki_filp->f_mapping; int error; =20 /* @@ -2239,15 +2235,14 @@ generic_file_buffered_read_pagenotuptodate(struct= kiocb *iocb, } else { error =3D 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; =20 - if (inode->i_blkbits =3D=3D PAGE_SHIFT || - !mapping->a_ops->is_partially_uptodate) + if (mapping->host->i_blkbits =3D=3D 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; =20 page_not_up_to_date: /* Get exclusive access to the page ... */ error =3D lock_page_for_iocb(iocb, page); - if (unlikely(error)) { - put_page(page); - return ERR_PTR(error); - } + if (unlikely(error)) + goto put_page; =20 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 =3D AOP_TRUNCATED_PAGE; + goto put_page; } =20 /* 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); =20 - error =3D filemap_readpage(iocb, page); - if (error) { - if (error =3D=3D AOP_TRUNCATED_PAGE) - return NULL; - return ERR_PTR(error); - } - return page; +put_page: + put_page(page); + return error; } =20 static struct page * @@ -2395,13 +2385,14 @@ static int generic_file_buffered_read_get_pages(s= truct kiocb *iocb, break; } =20 - page =3D generic_file_buffered_read_pagenotuptodate(iocb, - filp, iter, page, pg_pos, pg_count); - if (IS_ERR_OR_NULL(page)) { + err =3D generic_file_buffered_read_pagenotuptodate(iocb, + iter, page, pg_pos, pg_count); + if (err) { + if (err =3D=3D AOP_TRUNCATED_PAGE) + err =3D 0; for (j =3D i + 1; j < nr_got; j++) put_page(pages[j]); nr_got =3D i; - err =3D PTR_ERR_OR_ZERO(page); break; } } --=20 2.28.0