From patchwork Mon Aug 26 07:10:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13777253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8009FC54732 for ; Mon, 26 Aug 2024 07:02:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 613386B0138; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5766E6B0183; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 293286B0184; Mon, 26 Aug 2024 03:02:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 051E26B0138 for ; Mon, 26 Aug 2024 03:02:47 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 72BF5120C2A for ; Mon, 26 Aug 2024 07:02:47 +0000 (UTC) X-FDA: 82493503974.20.6741BC0 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id 4B3691C0007 for ; Mon, 26 Aug 2024 07:02:44 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=lizetao1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724655681; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JUX32vWtEN47faa/ptZN6HFUlLvoC/tlNsERX+PbF6A=; b=y64X4/9F+XOTQTG4SRhDcRsb8nu0OQ82ceG4HjWufTGGIK+mVhCfFl53Tip8FBG49l3fYP xemLSY4WFC919mkOybDEE9cVfJZ+kh876KhtnibkAJcypES0AhmLWVxBmj9VbSbP6VX7nj XLC5hXSMn3VACUICgPXlOWlhqIi+qOQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724655681; a=rsa-sha256; cv=none; b=0AEFPL6S7aixyQNAhacGBKKmUXUtc9wT7l8PEGhCUnSbHERyDPo5TL7DHDtY/5Z/PL/4sU Os8NR7SmVZR+ylDoDt2xnPtFGL1uVj0kbuUk6XoAmL2v8j7ZQSnwhqjLMKWqkR70WobxjZ RDzD50yTSe8yto23OS8wtOhXroIYyDs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of lizetao1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=lizetao1@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WshS52JC7z14G6b; Mon, 26 Aug 2024 15:01:57 +0800 (CST) Received: from kwepemd500012.china.huawei.com (unknown [7.221.188.25]) by mail.maildlp.com (Postfix) with ESMTPS id A0B5F1401F0; Mon, 26 Aug 2024 15:02:42 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemd500012.china.huawei.com (7.221.188.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 26 Aug 2024 15:02:42 +0800 From: Li Zetao To: , , , , CC: , , , Subject: [RFC PATCH -next 3/3] splice: Using scope-based resource instead of folio_lock/unlock Date: Mon, 26 Aug 2024 15:10:36 +0800 Message-ID: <20240826071036.2445717-4-lizetao1@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826071036.2445717-1-lizetao1@huawei.com> References: <20240826071036.2445717-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd500012.china.huawei.com (7.221.188.25) X-Rspamd-Queue-Id: 4B3691C0007 X-Stat-Signature: ymgundhbi6wijg8j8ifb3rrb9tw8w66y X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724655764-920289 X-HE-Meta: U2FsdGVkX1+L9uEDWPBqBjK1ut/BJQrmIsrCVoqctCPpRYXWFByBQPa05pu0Vzzc6s9QEaGw20ZIaN9g6Vhp1GIz2UPzwZjUA9Lnnc9796ZjVCO9p7dSThKiAs2sfjlvnApOyueqNVkZLo4nuSmtocufAuRZZC5wSs5nXoNwsolOSjp2vtMXWZpxWUebniVQoyofitYkA0TOubGbUqa6uyAGmE3oDIMCVscGPXR9BBiRTKcoy+lUzxJgjTZ+5s3qCtnNm0o/vB1pBEf0AwZh88xPQM4tgRL6c/02mNi0z8GSRmUAHh/ikiJu1kd+rr43Crm4qG3FNYqTnuvgR0IKQs6DXGhpIo+BvA4cNq4BLieLErZe6sMi9lQxET78uv+nwGJeRuS2IyvA0toVwYP5tsSnKOJojoQ0J2ETU71xKqv9bsNC79ksk5fAon+rX3TsWXE5NaFxgNJAt8VV5guSRYD7uPvslcyelLE5sfzT6Yc4OpNnAob+wOcV2POa7E85Y+IhXYrHjF/2mfUWHtdaax6dM4+SQeEZF7WnXh81oqeLgw3jmA4Z0/ZX0s65XYR944jhKUI1j3ANOMaejZuLcuRzeLF9kvrwAtO4eTOdJrprQzyRgSxCUPucinn36DhXl72yUSYO4RQFsjdDXhO19ucqUKkVdY0HXRrB+eMcjJNelKj+fIKokZCi26rifVKMKSxSLxK9Ft2smnlX08w5QtLDrZeOlTNa0YUFJbfItDGfhVXG1v3Tri3qqC8BsMox7fxsNjF8NM3tPJahHGEuhwdp++nTqqEptBgNaVTqZ9ohU6nsz1HI2IpWTQaseIKq9fQGQVxucxur5XaxLXpxuderMKo0UsRYLOOlB+IntQ63gkwUklDC563P0HSpDpA1vE3UriEooH1ewEWqVTBD+Oxl7J06Tt+73YRIDMUAo+E12eZ5ryrduBMcOjRCTnkRmreZJG36kGSVxKnHQ0w 9epYVVNh OKTjoty5GHM7/hUbA5VF5m3ANpYe47zNmarXqUtLH8Sl81jAIMzr2pH+gq45nDEQMBMaqls+E5LMwrgFrAg/dyWaY5Nkl3+iydrrHf2KrOhoMKe3yqFVkwgVQafJKtOH7k21N23B5U1ockejxv/vIXEU+AKnkMRnrVOofKKBKPHeXC8QyYlNN+jRkGT0XXAO7anvC 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: List-Subscribe: List-Unsubscribe: Use guard() to manage locking and unlocking a folio, thus avoiding the use of goto unlock code. Remove the out_unlock and error label, and return directly when an error occurs, allowing the compiler to release the folio's lock. Signed-off-by: Li Zetao --- fs/splice.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/fs/splice.c b/fs/splice.c index 06232d7e505f..bf976f2edfc1 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -120,36 +120,25 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe, struct pipe_buffer *buf) { struct folio *folio = page_folio(buf->page); - int err; if (!folio_test_uptodate(folio)) { - folio_lock(folio); + guard(folio)(folio); /* * Folio got truncated/unhashed. This will cause a 0-byte * splice, if this is the first page. */ - if (!folio->mapping) { - err = -ENODATA; - goto error; - } + if (!folio->mapping) + return -ENODATA; /* * Uh oh, read-error from disk. */ - if (!folio_test_uptodate(folio)) { - err = -EIO; - goto error; - } - - /* Folio is ok after all, we are done */ - folio_unlock(folio); + if (!folio_test_uptodate(folio)) + return -EIO; } return 0; -error: - folio_unlock(folio); - return err; } const struct pipe_buf_operations page_cache_pipe_buf_ops = {